Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 774 Bytes

counter-child-function.mdx

File metadata and controls

30 lines (24 loc) · 774 Bytes

import { State, Observe } from '../es';

Counter

<State initialState={{ count: 0 }}> {({ setState, ...state }) => { // cannot leave blank lines here // but at least we can use JS variables because we are inside a function! const increment = 1; // no blank lines here either // you can use comments or a single ; return ( // the body of the document can be put inside the render function // this has to be wrapped in a fragment if it has multiple nodes // // code inside the block cannot be indented >= 4 spaces or it will be // rendered as text instead of parsed <React.Fragment>

<button onClick={() => setState(s => ({ count: s.count + increment }))}> Click me

The button has been clicked:

{state.count} times

</React.Fragment> )}}