This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeEntity } from 'react-entities'; | |
import * as counter from './counter' | |
export const useCounter = makeEntity(counter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useCallback } from 'react'; | |
import { useCounter } from './entities'; | |
const CounterView = () => { | |
const [counter, { increment, decrement }] = useCounter(); | |
const handleClickIncrement = useCallback(() => increment(), []); | |
const handleClickDecrement = useCallback(() => decrement(), []); |