Skip to content

Instantly share code, notes, and snippets.

@Celeo
Last active March 22, 2020 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Celeo/4ced161b82e8f029b1e1240abaa978f6 to your computer and use it in GitHub Desktop.
Save Celeo/4ced161b82e8f029b1e1240abaa978f6 to your computer and use it in GitHub Desktop.
Simple example of using pullstate
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
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