Comments (17)
The upgrade guide only says you need to do this, which is what I have translated above
// Before
import { hydrate } from 'react-dom';
const container = document.getElementById('app');
hydrate(<App tab="home" />, container);
// After
import { hydrateRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = hydrateRoot(container, <App tab="home" />);
// Unlike with createRoot, you don't need a separate root.render() call here.
Maybe you need to update the server too? But again, reactwg/react-18#22 mentions nothing.
from fable-react.
@forki, aha. reactwg/react-18#5
If you want to update a root again after hydration, you can save it to a variable, just like with createRoot, and call root.render() later:
The fact that it said you didn't need a separate render call confused me. So hydrateRoot
also returns a root that you use to render in every setState
call I guess?
from fable-react.
It worked thanks
from fable-react.
Yup, I intend to create a PR for elmish-react tonight to use the new API when React 18 is detected. I believe you can ignore the warning for now.
from fable-react.
@forki, but if you're in a hurry, you can try defining this yourself and calling it instead of Program.withReactHydrate
.
let withReactHydrateUsing lazyView2With placeholderId (program:Elmish.Program<_,_,_,_>) =
let setState model dispatch =
ReactDomClient.hydrateRoot (
Browser.Dom.document.getElementById placeholderId,
lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch
)
program
|> Program.withSetState setState
let withReactHydrate placeholderId (program:Elmish.Program<_,_,_,_>) =
withReactHydrateUsing lazyView2With placeholderId program
In fact, it would actually help me later if you could check it works.
from fable-react.
from fable-react.
Hmm, unfortunately I have no experience with SSR. I do wonder why it says you are calling createRoot
though.
from fable-react.
Hi my code keeps logging this err, any idea of how I can fix it?
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17
from fable-react.
If you use Fable.React 8+, you should not see that message.
from fable-react.
Didn't solve it
from fable-react.
@fourglobe302500, sorry I meant Fable.Elmish.React 4.0.0-beta-2.
from fable-react.
Thanks a lot for the help @kerams and @fourglobe302500 for confirming! 👍 Let's close this then, please reopen if you still have issues.
from fable-react.
I'm having very similar warning but for ReactDOM.render
:
ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
This is via using Fable.React.Helpers.mountById
, am I supposed to use something else?
Here is my paket.lock
STORAGE: NONE
NUGET
remote: https://api.nuget.org/v3/index.json
Fable.AST (4.3) - restriction: >= netstandard2.0
Fable.Browser.Blob (1.3) - restriction: >= netstandard2.0
Fable.Core (>= 3.0) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Browser.Dom (2.15)
Fable.Browser.Blob (>= 1.3) - restriction: >= netstandard2.0
Fable.Browser.Event (>= 1.5) - restriction: >= netstandard2.0
Fable.Browser.WebStorage (>= 1.2) - restriction: >= netstandard2.0
Fable.Core (>= 3.2.8) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Browser.Event (1.5) - restriction: >= netstandard2.0
Fable.Browser.Gamepad (>= 1.1) - restriction: >= netstandard2.0
Fable.Core (>= 3.0) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Browser.Gamepad (1.2) - restriction: >= netstandard2.0
Fable.Core (>= 3.0) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Browser.WebStorage (1.2) - restriction: >= netstandard2.0
Fable.Browser.Event (>= 1.5) - restriction: >= netstandard2.0
Fable.Core (>= 3.0) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Core (4.2)
Fable.Elmish (4.1) - restriction: >= netstandard2.0
Fable.Core (>= 3.7.1) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Elmish.HMR (7.0)
Fable.Core (>= 3.7.1) - restriction: >= netstandard2.0
Fable.Elmish.React (>= 4.0) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.Elmish.React (4.0) - restriction: >= netstandard2.0
Fable.Elmish (>= 4.0) - restriction: >= netstandard2.0
Fable.ReactDom.Types (>= 18.0) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.FontAwesome (3.0) - restriction: >= netstandard2.0
Fable.Core (>= 3.7.1) - restriction: >= netstandard2.0
Fable.React (>= 9.2) - restriction: >= netstandard2.0
Fable.FontAwesome.Free (3.0)
Fable.Core (>= 3.7.1) - restriction: >= netstandard2.0
Fable.FontAwesome (>= 3.0) - restriction: >= netstandard2.0
Fable.React (>= 9.2) - restriction: >= netstandard2.0
Fable.React (9.3)
Fable.React.Types (>= 18.3) - restriction: >= netstandard2.0
Fable.ReactDom.Types (>= 18.2) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.React.Types (18.3) - restriction: >= netstandard2.0
Fable.Browser.Dom (>= 2.4.4) - restriction: >= netstandard2.0
Fable.Core (>= 3.2.7) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Fable.ReactDom.Types (18.2) - restriction: >= netstandard2.0
Fable.React.Types (>= 18.3) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Feliz (2.7)
Fable.ReactDom.Types (>= 18.2) - restriction: >= netstandard2.0
Feliz.CompilerPlugins (>= 2.2) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Feliz.CompilerPlugins (2.2) - restriction: >= netstandard2.0
Fable.AST (>= 4.2.1) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
Feliz.Recharts (4.2)
Feliz (>= 2.3) - restriction: >= netstandard2.0
FSharp.Core (>= 4.7.2) - restriction: >= netstandard2.0
FSharp.Core (8.0.100)
Fulma (3.0)
Fable.Core (>= 3.7.1) - restriction: >= netstandard2.0
Fable.React (>= 9.2) - restriction: >= netstandard2.0
from fable-react.
@smoothdeveloper You are supposed to use createRoot
which mountById
doesn't use (yet?).
Example: https://github.com/elmish/react/blob/v4.x/src/react.fs#L23C15-L49
I suppose we could make Fable.React.Helpers.mountById
detect the version of React and use the expected API based on that without introducing a breaking change.
from fable-react.
@MangelMaxime thanks, for now I can still try to figure out what I'm doing (very new to the F# on browser frontend) and hope I can better understand the react stuff and the whole underlying stuff.
I also need to refresh the element and I'm not sure mountById
is the correct call.
I've tried with the Feliz ReactDOM
helper and end up having no warning on initial mount, but when I refresh the ReactDOM.createRoot
and render
calls cause another warning.
You are calling ReactDOMClient.createRoot() on a container that has already been passed to createRoot() before. Instead, call root.render() on the existing root instead if you want to update it.
But this is maybe specific to the Feliz helper, not this repository.
I suppose we could make Fable.React.Helpers.mountById detect the version of React and use the expected API based on that without introducing a breaking change.
Having a custom warning for fable-react users that guide how to transform the call in F# terms would be great to guide the users that aren't necessarily familar with the react thing.
I'll spend time looking at the elmish and fable-react documentation to level up a bit.
from fable-react.
But this is maybe specific to the Feliz helper, not this repository
This is because if you try to call twice createRoot
on the same element then React complains. He is telling you that you are doing twice the same things.
If I remember correctly, React expects you to either update the existing root
or destroy the previous one and then instantiate the new one.
from fable-react.
@MangelMaxime, thanks, it sounds I need to keep track of the instanciated roots in some form of state, and use/reuse those then.
from fable-react.
Related Issues (20)
- React Server Components integration HOT 2
- Can't figure out how to wrap my view with a Higher Order Component HOT 4
- JsInterop helper for wrapping a higher order component HOT 2
- Can't reference React in Fable HOT 2
- Fable.ReactServer.cssProp very slow HOT 4
- Add Custom DU to DOMAttr HOT 1
- FunctionComponent.Lazy and SSR HOT 1
- Update samples to Fable 3
- Can't update shared state passed with useContext? HOT 3
- Q: Use ReactElement import member for Storybook HOT 3
- Missing 'open' from Fable.React.Props? HOT 2
- Last Fable.React upgrade breaks my code HOT 7
- Publish source files from Fable.React.Types and Fable.ReactDom.Types to nuget HOT 5
- Fable.React version 8 depends on React.Dom gte 18 lt 19 according to femto
- Add Pointer Events HOT 3
- Why is useCallback not implemented? HOT 3
- How to obtain a component ref in a function component? HOT 5
- FunctionComponent.Of functions cache breaks reusable code HOT 1
- voidEl breaks with: $ELEMENT is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fable-react.