DEV Community

Discussion on: You Can Definitely Use Global Variables To Manage Global State In React

Collapse
 
supunkavinda profile image
Supun Kavinda • Edited

We use your state-pool in our production application (quite a large one) and it's working great. Thank you for the work!

However, we have written an extended version of useGlobalState like this.

export default function useGlobalStateExtended(key, def) {
    const [x, update, set] = useGlobalState(key, {
        default: def
    });
    return [x, set];
}
Enter fullscreen mode Exit fullscreen mode

It allows us to easily define a default in the param, without adding it inside an object. And, returns only the value and set function (we are not interested in the update function). Btw, looks like you have made a change to the return value. The version we use returns [value, update, set] but in your example here it's changed to [value, set, update]. It's good move.

This is a great library to solve a lot of headaches in React applications.

Collapse
 
yezyilomo profile image
Yezy Ilomo

Glad to know that you are using state-pool in production. The change was made in v0.4.0, I think [state, setState, updateState] makes more sense than [state, updateState, setState], it was also influenced by [state, setState] from useState since we don't want state-pool's API to be very different from react state hook's API.