Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@feige0629/react-common-store

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feige0629/react-common-store

```tsx yarn add @feige0629/react-common-store

latest
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

1、使用方法

yarn add @feige0629/react-common-store

npm install @feige0629/react-common-store

调用

import * as React from "react";
import { StoreRoot } from "@feige0629/react-common-store";

export default function App() {
    return (
        <StoreRoot>
            ...
        </StoreRoot>
    );
}

定义数据

import { initState, compute } from "@feige0629/react-common-store";

export const $showGuides = initState<boolean>(true);
export const $selectedFlattenLayers = compute(({ get }) => {
    const layerManager = get($layerManager)!;
    const selectedLayers = get($selectedLayers)!;

    return layerManager.toFlatten(selectedLayers);
});

使用

import { useStoreRoot, useStoreStateSetPromise, useStoreStateValue, useStoreValue, useStoreState } from "@feige0629/react-common-store";
import { $showGuides, $selectedFlattenLayers } from "./stores";

// 第一种
const root = useStoreRoot();
const layers = root.get($layers);
root.set($layers, '新数据');


// 第二种
useStoreValue($showGuides, '新数据'); // 绑定全局数据

const showGuidesStore = useStoreValue($showGuides); // 获取数据
const value = showGuidesStore.value;

showGuidesStore.update(value); // 设置数据

// 第三种
const showGuidesStore = useStoreStateValue($showGuides); // 仅仅用来获取数据

// 第四种
const showGuidesStore = useStoreStateSetPromise($showGuides);
showGuidesStore('新数据').then(complete => { // 设置数据
    if (!complete) {
        return false;
    }
    
    ....

    return complete;
});

// 第五种
const [guidelines, setGuidelines] = useStoreState($showGuides);
guidelines // 获取数据
setGuidelines('新数据') // 设置数据

// 第六种
const setShowGuidesValue = useStoreStateSetValue($showGuides);
setShowGuidesValue('新数据') // 设置数据

FAQs

Package last updated on 10 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts