react-parent-state
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Parent state

installation

yarn add react-parent-state
import {ParentState, useParentState} from "react-parent-state";


function Counter() {
    const [count] = useParentState();
    return <div>{count}</div>
}

function UpdateCounter() {
    const [, updateCount] = useParentState<number>();
    return <button onClick={() => updateCount(x => x + 1)}>Increment</button>
}

export function App() {
    return (
        <div>
            <ParentState value={1}>
                <Counter />
                <UpdateCounter />
            </ParentState>
        </div>
    )
}

// or with extended props

export function App(props) {
    return (
        <div>
            {/* watch option will watch property changes and update the state accordingly */}
            <ParentState value={props} watch>
                <Counter />
                <UpdateCounter />
            </ParentState>
        </div>
    )
}

Package Sidebar

Install

npm i react-parent-state

Weekly Downloads

15

Version

1.0.1

License

MIT

Unpacked Size

2.98 kB

Total Files

6

Last publish

Collaborators

  • adil.sudo