How to use the @hookstate/core.useStateLink function in @hookstate/core

To help you get started, we’ve selected a few @hookstate/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avkonst / hookstate / examples / src / examples / plugin-initial-statefragment.tsx View on Github external
export const ExampleComponent = () => {
    const state = useStateLink(['First Task', 'Second Task'])
        .with(Initial); // enable the plugin
    return <>
         Initial(s).modified())}
        >{(modified: boolean) => {
            return <p>
                Last render at: {(new Date()).toISOString()} <br>
                Is whole current state modified (vs the initial): {modified.toString()} <br>
                The <b>initial</b> state: {JSON.stringify(Initial(state).get())}
            </p>
        }}
        
        {state.nested.map((taskState, taskIndex) =&gt;
            {scopedTaskState =&gt; {
                return <p></p>
github avkonst / hookstate / examples / src / examples / local-complex-from-documentation.tsx View on Github external
function JsonDump(props: { state: StateLink }) {
    // optional scoped state for performance, could use props.state everywhere instead
    const state = useStateLink(props.state);
    return <p>
        Last render at: {(new Date()).toISOString()} <br>
        Current state: {JSON.stringify(state.value)}
    </p>
}
github avkonst / hookstate / examples / src / examples / performance-demo-large-table.tsx View on Github external
function PerformanceMeter(props: { matrixState: StateLink }) {
    const stats = React.useRef({
        totalSum: 0,
        totalCalls: 0,
        startTime: (new Date()).getTime()
    })
    const elapsedMs = () =&gt; (new Date()).getTime() - stats.current.startTime;
    const elapsed = () =&gt; Math.floor(elapsedMs() / 1000);
    const rate = Math.floor(stats.current.totalCalls / elapsedMs() * 1000);
    const scopedState = useStateLink(props.matrixState)
        .with(() =&gt; ({
            id: PerformanceViewPluginID,
            instanceFactory: () =&gt; ({
                onPreset: (path, prevState, newCellValue) =&gt; {
                    if (path.length === 2) {
                        // new value can be only number in this example
                        // and path can contain only 2 elements: row and column indexes
                        stats.current.totalSum += newCellValue - prevState[path[0]][path[1]];
                    }
                },
                onSet: () =&gt; {
                    stats.current.totalCalls += 1;
                }
            })
        }))
    // mark the value of the whole matrix as 'used' by this component
github avkonst / hookstate / experimental / ie11 / src / Example.tsx View on Github external
function TaskEditor(props: { taskState: StateLink }) {
    // optional scoped state for performance, could use props.taskState everywhere instead
    const taskState = useStateLink(props.taskState);
    return <p>
        Last render at: {(new Date()).toISOString()} <br>
        Task state: {JSON.stringify(taskState.get())}<br>
        <input value="{taskState.nested.name.get()}"> taskState.nested.name.set(e.target.value)}
        /&gt;
        <button> taskState.nested.priority.set(p =&gt; (p || 0) + 1)} &gt;
            Increase priority
        </button>
    </p>
}
github avkonst / hookstate / examples / src / examples / global-complex-from-documentation.tsx View on Github external
function TaskEditor(props: { taskState: StateLink }) {
    // optional scoped state for performance, could use props.taskState everywhere instead
    const taskState = useStateLink(props.taskState);
    return <p>
        Last render at: {(new Date()).toISOString()} <br>
        Task state: {JSON.stringify(taskState.get())}<br>
        <input value="{taskState.nested.name.get()}"> taskState.nested.name.set(e.target.value)}
        /&gt;
        <button> taskState.nested.priority.set(p =&gt; (p || 0) + 1)} &gt;
            Increase priority
        </button>
    </p>
}
github avkonst / hookstate / examples / src / examples / global-multiple-consumers-from-root.tsx View on Github external
const TaskView = (props: { state: StateLink }) =&gt; {
    const state = useStateLink(props.state);
    return <p>
        Last render at: {(new Date()).toISOString()} <br>
        <span>Task name: {state.value} </span>
        <input value="{state.value}"> state.set(e.target.value)}/&gt;
    </p>
}
github avkonst / hookstate / plugins / Prerender / dist / index.js View on Github external
function ScopedPrerender(props) {
    var scoped = core.useStateLink(props.state);
    return props.children(scoped);
}
github avkonst / hookstate / examples / src / examples / global-multiple-consumers.tsx View on Github external
const JsonDump = () =&gt; {
    const state = useStateLink(stateRef);
    return <p>
        Last render at: {(new Date()).toISOString()} <br>
        Current state: {JSON.stringify(state.value)}
    </p>
}
github avkonst / hookstate / examples / src / examples / global-multiple-consumers-from-root.tsx View on Github external
export const ExampleComponent = () =&gt; {
    const state = useStateLink(stateRef)
    return &lt;&gt;
        
        
        
    
}
github avkonst / hookstate / examples / src / examples / plugin-touched.tsx View on Github external
function TaskEditor(props: { taskState: StateLink }) {
    const taskState = useStateLink(props.taskState);
    return <p>
        Last render at: {(new Date()).toISOString()} <br>
        Is this task touched: {Touched(taskState).touched().toString()} <br>
        <input value="{taskState.get()}"> taskState.set(e.target.value)}
        /&gt;
    </p>
}

@hookstate/core

The flexible, fast and extendable state management for React that is based on hooks and state usage tracking.

MIT
Latest version published 2 years ago

Package Health Score

63 / 100
Full package analysis

Similar packages