using ink with valtio #535
Answered
by
airjp73
chrisdrackett
asked this question in
Q&A
|
I'm trying to use ink with valtio (https://github.com/pmndrs/valtio) and so far haven't had any luck. Ink just isn't rendering when state updates. Here is a minimal example: https://replit.com/@chrisdrackett/ink-valtio-test?v=1 and the same thing in react-dom: https://codesandbox.io/s/hardcore-shirley-3yq42m?file=/src/App.tsx |
Answered by
airjp73
Nov 19, 2022
Replies: 1 comment 1 reply
|
I've run into the same issue, but using I think the issue is actually in the Hopefully this will be fixed when ink adds React 18 support? There are a couple workarounds I've found:
const { rerender } = render(<ComponentWithXstate />);
xstateService.onTransition(() => rerender(<ComponentWithXstate />);
// This is the entry file to your whole CLI
const noOp = () => {
throw new Error("This is just a shim -- it shouldn't be called");
};
(globalThis as any).window = {
// Tricks use-sync-external-store into using the client shim
// instead of the server shim
document: { createElement: noOp },
// Surpresses a warning about needing to polyfill these
requestAnimationFrame: noOp,
cancelAnimationFrame: noOp,
};
// Might need to use require if you're using CommonJS
// I'm using ES modules in my project so this is what I'm doing.
import("./real-entry-file"); |
1 reply
Answer selected by
vadimdemedes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've run into the same issue, but using
xstateinstead.I think the issue is actually in the
use-sync-external-storeshim used by bothxstateandvaltio. That shim has a server and client version, and since ink is running outside the browser, it uses the server version. That just returns the initial state.Hopefully this will be fixed when ink adds React 18 support?
There are a couple workarounds I've found:
valtiopersonally, but I'm sure theres a similar API you can use.window.document.createElement./…