Takes an aribtrary React hook and makes it globally stateful.
It's like 12 lines of code, so you should probably just copy the source rather than include this in your package.json. 🤷♂️
import React from "react";
import ReactDOM from "react-dom";
import createGlobalHook from "create-global-hook";
const [hook, Provider] = createGlobalHook((value: number) =>
React.useState(value)
);
const App = () => {
const [state, setState] = hook();
};
const OtherApp = () => {
const [state, setState] = hook();
};
ReactDOM.render(
<Provider value={0}>
<App />
<OtherApp />
</Provider>,
document.getElementById("root")
);