reason-react
reason-react copied to clipboard
ReactDOMRe.render should return something
ReactDOM.render actually returns an object (containing amongst other things a render function which can be used to update the properties of the rendered component at runtime). Because the type definition says the return type is unit, the compiler doesn't add a return statement which means the value is thrown away and can't be used by the rendering context.
This can be fixed with an extra function (with a different name so existing implementations don't break):
[@bs.val] [@bs.module "react-dom"] external renderWithReturn: (React.element, Dom.element) => 'a = "render";
Do you have a use-case for that?
The issue is that ReactDOM.render returns whether:
- a DOM node if your render a DOM component
nullif you render a function component (which is the default with ReasonReact)- a reference to the component in case of component classes.
We cannot infer the return type from React.element.
Given how rarely this is used, I'd advice for users who really want to do that to write their own external like the one you added.
To be honest, I thought I had a use case, but it turned out to be satisfied by simply re-rendering the component in the same container.
Not sure how's worth adding an external like renderWithReturn considering that most APIs might change for React 17/18.
I will close now since it seems like isn't being needed, but happy to discuss further if more cases appear.