Skip to content

Instantly share code, notes, and snippets.

View arnelenero's full-sized avatar

Arnel Enero arnelenero

View GitHub Profile
@arnelenero
arnelenero / CounterView.js
Created August 2, 2019 15:26
React Entities example - CounterView component
import React, { useCallback } from 'react';
import { useCounter } from './entities';
const CounterView = () => {
const [counter, { increment, decrement }] = useCounter();
const handleClickIncrement = useCallback(() => increment(), []);
const handleClickDecrement = useCallback(() => decrement(), []);
@arnelenero
arnelenero / index.js
Created August 2, 2019 15:21
React Entities example: entities/index.js
import { makeEntity } from 'react-entities';
import * as counter from './counter'
export const useCounter = makeEntity(counter);
@arnelenero
arnelenero / counter.js
Last active August 2, 2019 15:22
React Entities example: entities/counter.js
export const initialState = {
value: 0
};
export function increment() {
this.setState({ value: this.state.value + 1 });
}
export function decrement() {
this.setState({ value: this.state.value - 1 });