-
Notifications
You must be signed in to change notification settings - Fork 329
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
Custom Renderer in React 18 #950
Comments
I haven't investigated much in React 18 yet, but I think this is the equivalent of render: https://codesandbox.io/s/quizzical-pare-nnunmt?file=/src/App.tsx Although I feel like you may need to make sure you don't create the root multiple times. Maybe the right approach is via a Portal? |
@Haroenv cheers for looking into this. Looks like, unfortunately, your potential fix is rendering the items in body rather than the search component: In any case, i'll give your example a try locally and see if I have any luck. Re: creating a root multiple times, I think you're right there too. When trying this locally before I was getting errors about the root already being instantiated and to call Perhaps the root needs to be defined outside of the effect or be removed in the effect clean-up? |
We'll make sure to update these guides soon, but for now you can either
Hope that helps! |
Could you perhaps elaborate on this a touch? Or the third option. Perhaps an example. I don't want my entire application to run in react 17 mode, I'm not super versed in algolia's component structure. Thanks |
Only the autocomplete part would run in React 17 mode, as it's a separate root, but I see indeed how you'd want to avoid the issue. For option 1, autocomplete-core, here's an example: https://codesandbox.io/s/frosty-hooks-ptzbc5 which is slightly modified from the examples in this repository (react-renderer) to use React 18 and runs without warnings For option 3, you can follow the guide on https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/templates/#returning-html combined with a regular |
I see, I understand now then, I'm ok if the autocomplete uses react 17 for now, I wasn't aware the scope was limited. Thanks a lot! Thanks for the other explanations as well. Helped a lot. |
@nathnhughes @savager You shouldn't create the root on the same container that you pass to the Autocomplete lets you pass a Therefore, you can create the root in there once by storing it in a ref, then render in it: https://codesandbox.io/s/elated-danilo-0itu34?file=/src/App.tsx Autocomplete will warn against using the Regarding warnings about |
Description
Adding a custom renderer in React 18 seems to throw a couple of errors, namely:
createElement
are no longer compatibleReactDOM.render
is no longer supported in React 18 and forces the app to behave as if it's running React 17 until the method is removedReproduction
https://codesandbox.io/s/morning-fire-tqxpqs?file=/src/App.tsx
Steps
Additionally, using createElement throws the following type error:
However this doesn't seem to appear in the reproduction (probably due to the package versions, see Notes section).
Expected behavior
The component should work without
createRoot
error and should not prevent React 18 from being used.Environment
@algolia/[email protected]
[email protected]
[email protected]
[email protected]
Notes
18.0.0-alpha-fd5e01c2e-20210913
and the latest version of React-DOM is:18.0.0-alpha-fd5e01c2e-20210913
. This may result in slightly different behavior to my local environment which is running v18.0.0 for both packages.createRoot
as the console error suggests.Example code
For context, an example snippet of my production code that is experiencing the errors can be seen below:
The text was updated successfully, but these errors were encountered: