Last active
March 22, 2020 02:27
-
-
Save Celeo/4ced161b82e8f029b1e1240abaa978f6 to your computer and use it in GitHub Desktop.
Simple example of using pullstate
This file contains hidden or 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 from 'react' | |
import { useStoreState } from "pullstate" | |
import { UIStore } from "./store" | |
function App() { | |
const name = useStoreState(UIStore, s => s.name) | |
const onChange = (event) => { | |
const newVal = event.target.value | |
UIStore.update(s => { | |
s.name = newVal | |
}) | |
} | |
return ( | |
<div> | |
<h2>App</h2> | |
<p>Name is: { name }</p> | |
<input type="text" onChange={onChange}></input> | |
</div> | |
) | |
} | |
export default App |
This file contains hidden or 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 { Store } from "pullstate"; | |
export const UIStore = new Store({ | |
name: "" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment