Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify low level API #162

Closed
yezyilomo opened this issue Feb 20, 2023 · 0 comments
Closed

Simplify low level API #162

yezyilomo opened this issue Feb 20, 2023 · 0 comments

Comments

@yezyilomo
Copy link
Owner

yezyilomo commented Feb 20, 2023

Remove "Global" word in low level API because this is implied when you’re creating your state at the global scope. Also state-pool can be used to manage local state too, it’s just of the matter of where you’re declaring your state. So the new low level API will be as

For state creation

const user = createState();

Instead of

const user = createGlobalState();

For state consumption

[user, setUser] = user.useState();

Instead of

[user, setUser] = useGlobalState(user);

For state consumption with reducer

[user, setUser] = user.useReducer();

Instead of

[user, setUser] = useGlobalStateReducer(user);

What if I want to use the old API form

So if you want to use the old API form you could do it as

import {createState, useState} from "state-pool";

const name = createState();

function Component(){
    const [name, setName] = useState(name);

    // Or for useReducer as
    const [name, setName] = useReducer(reducer, name);

    // other stuff…..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant