I'm having a hard time figuring out client-side interactivity with HydrationRoot #3
Unanswered
finestgecko
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Putting them in subfolders should work fine, at least it does so for me. Do you mind sharing the contents of |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm relatively new to SSR (coming from Inertia) and I noticed that client-side interactivity doesn't work right away. I understand that in order to make those components work, I need to wrap it in
<HydrationRoot>
. Until now, I haven't been able to figure out how to make a simple counter work.Here is a quick example:
MyView.tsx:
Counter.tsx:
When I click "increment", nothing happens.
(Also, I get a TypeScript error on the
component
prop inHydrationRoot
:Type 'string' is not assignable to type 'never'.
)Referring to the input component example example in the docs, I can see that the
useHydrated
hook is being used to first check if the component has been hydrated. I tried toconsole.log
that:(this is from another component, not the counter)
So we can deduce that it isn't being hydrated.
I have a feeling I'm doing something wrong here - if so, would appreciate if someone could point it out.
Even though the concept of hydration isn't unique to Radonis, I think the docs could benefit from more explanation around this aspect. Perhaps even a simple demo project of Radonis in general.
Update: I figured it out. For anyone else wondering the same, I came across this in the docs:
I was putting components in individual folders, e.g.
resources/components/Modals/UserModal.tsx
, but apparently this doesn't work.I placed the component directly in the resources directory, e.g.
resources/components/Counter.tsx
and now client-side interactivity works (and the TypeScript error goes away).The question now is:
HydrationRoot
with a more complex component like a modalBeta Was this translation helpful? Give feedback.
All reactions