-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Remix + Vite unable to use client only libs #9019
Comments
From a quick glance, it looks like this library uses
Instead, you want to avoid running this hook until after hydration - which you can do with the remix-utils ClientOnly component: import { useNetworkState } from "@uidotdev/usehooks";
import { ClientOnly } from "remix-utils/client-only";
export default function Index() {
return (
<div>
<NetworkState />
<ClientOnly>{() => <NetworkState />}</ClientOnly>
</div>
);
}
function NetworkState() {
return <pre>{JSON.stringify(useNetworkState())}</pre>;
} |
@brophdawg11 should I open a new issue or discussion about my doubt? |
I would see if the |
@brophdawg11 how would you use hook in this case? Can you elaborate before closing? |
You can call a hook anywhere you want in a compnent as long as it's not called conditionally. I put it in stringify here just for the simple example, most folks would call it at the top of the function so it's more obvious: function NetworkState() {
let network = useNetworkState()
return <pre>{JSON.stringify(network)}</pre>;
} |
Thanks @brophdawg11
|
Reproduction
I am using a client hooks lib and everything works fine without vite, once setting up vite I get the error of
"... is a client-only hook"
. I tried adding the lib tooptimizeDeps
same issue which is strange.Tried using
_.client.ts
no luck.Tried ssr: { external: 'client-lib' } no luck either.
Here is a simple repo with the initial settings.
There you can see the configuration for vite with the lib, and on root is where I am using the lib.
https://github.com/yarapolana/remix-vite-client-libs
System Info
Used Package Manager
yarn
Expected Behavior
Ability to use client only libs without issues.
Actual Behavior
Error with "... is a client only hook" and no steps to fix it.
The text was updated successfully, but these errors were encountered: