How to use the @hookstate/core.useStateLinkUnmounted 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 / experimental / ie11 / src / Example.tsx View on Github external
setTimeout(() => useStateLinkUnmounted(stateInf)
    .set(tasks => tasks.concat([{ name: 'Second task by timeout', priority: 1 }]))
, 5000) // adds new task 5 seconds after website load
github avkonst / hookstate / examples / src / examples / global-object.tsx View on Github external
setInterval(() => useStateLinkUnmounted(store) // get to the state of the object
    .nested.counter // get to the state of the counter property
    .set(p => p + 1) // increment the counter...
, 3000) // ...every 3 seconds
github avkonst / hookstate / examples / src / examples / plugin-persistence2.tsx View on Github external
interface ServiceMessageLeaderId {
    readonly version: number;
    readonly kind: 'leader-elected';
    readonly id: number;
}

type ServiceMessage = ServiceMessageInitialRequest | ServiceMessageLeaderId;

const PluginID = Symbol('Broadcasted');

class BroadcastedPluginInstance implements PluginInstance {
    private broadcastRef: BroadcastChannelHandle;
    private isBroadcastEnabled = true;
    private statusStateRef = createStateLink({ isLoading: true, isLeader: false });
    private statusState = useStateLinkUnmounted(this.statusStateRef);
    private instanceId = -1;
    
    constructor(
        readonly topic: string,
        readonly unmountedLink: StateLink,
        readonly onLeader?: () => Promise
    ) {
        this.broadcastRef = subscribeBroadcastChannel(topic, (message: BroadcastMessage | ServiceMessage) => {
            if (message.version > 1) {
                // peer tab has been upgraded
                return;
            }
            if ('kind' in message) {
                if (this.statusState.value.isLeader && message.kind === 'request-initial') {
                    this.broadcastRef.channel.postMessage({
                        version: 1,
github avkonst / hookstate / examples / src / examples / global-complex-from-documentation.tsx View on Github external
setTimeout(() => useStateLinkUnmounted(stateRef)
    .set(tasks => tasks.concat([{ name: 'Second task by timeout', priority: 1 }]))
, 5000) // adds new task 5 seconds after website load
github avkonst / hookstate / examples / src / examples / global-complex.tsx View on Github external
setInterval(() => useStateLinkUnmounted(store)
    .nested[0] // get to the state of the first array element
    .nested.counter // get to the state of the element's counter
    .set(p => p + 1) // increment the counter...
, 3000) // ...every 3 seconds
github avkonst / hookstate / experimental / sizetest / src / Example.tsx View on Github external
import React from 'react';
import { createStateLink, useStateLink, useStateLinkUnmounted } from '@hookstate/core';

const store = createStateLink(0);

useStateLinkUnmounted(store);

export const ExampleComponent = () => {
    const state = useStateLink(store);
    return <>{state.value}
}
github avkonst / hookstate / examples / src / examples / global-getting-started.tsx View on Github external
setInterval(() => useStateLinkUnmounted(stateRef).set(p => p + 1), 3000)
github avkonst / hookstate / examples / src / examples / global-array.tsx View on Github external
setInterval(() => useStateLinkUnmounted(store).nested[0].set(p => p + 1), 3000)

@hookstate/core

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

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis

Similar packages