Skip to content

Instantly share code, notes, and snippets.

// hooks/useUser.js
export const getUser = async ({ id }) => {
const { data, error } = await db
.from('users')
.select('*')
.eq('id', id)
.single();
if (error) {
throw new Error(error.message)
@marcincodes
marcincodes / multiple-use-effect-issue.js
Last active May 27, 2021 12:40
Setting state in parent lead to multiple useEffect runs
function Root() {
const [increment, setIncrement] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setIncrement((inc) => inc + 1);
}, 3000);
return () => clearInterval(interval);
}, []);
@marcincodes
marcincodes / machine.js
Created April 22, 2021 09:36
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'toggle',
initial: 'inactive',
states: {
inactive: { on: { TOGGLE: 'active' } },
active: { on: { TOGGLE: 'inactive' } }
}
})
$tickets object Ticket (20)
object (20)
Available methods (165)
Static class properties (10)
protected connection -> NULL
protected table -> NULL
@extends('layout')
@section('content')
@foreach($tickets as $ticket)
{{ $ticket->id }}
@endforeach
@stop
$tickets object Ticket (20)
object (20)
Available methods (165)
Static class properties (10)
protected connection -> NULL
protected table -> NULL
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('initDB'); // We can remove this line after we're finished
}
public function initDB() {
$group = $this->User->Group;
// Allow admins to everything
$group->id = 1;
//Theard
public $validate = array(
'name' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
//add ctp
<div class="add topic form">
<?php echo $this->Form->create('Theard'); ?>
<fieldset>
<legend><?php echo __('Add Topic'); ?></legend>
<?php
echo $this->Form->input('name');
echo $this->Form->input('Post.body');
?>
</fieldset>
//debug
array(
(int) 0 => array(
'Theard' => array(
'id' => '1',
'name' => 'Pierwszy post testowy 1',
'slug' => 'pierwszy-post-testowy-1',
'body' => 'body',
'by' => 'PerfectM',
'date' => '2013-10-17 12:31:48',