Proposal: Remove React.DOM (dom component factories) API and release as new module
See original GitHub issueThe React.DOM
API (not to be confused with ReactDOM
) does not make sense in the greater scheme of the React API being used in other rendering environments like React Native or GL or <insert anything that isn’t the DOM>. The React.*
API is meant to be universal in that sense. We are never going to add React.iOS.
However, these factories don’t actually have any implementation details that rely on actual DOM details, they essentially just map like so: React.DOM.div = (...args) => React.createElement('div', ...args)
, which is why they ended up in the universal React package and not in ReactDOM.
This would only impact people who don’t currently use JSX and have held out using the function call syntax. <div/>
now (and has for over a year) transforms to React.createElement('div')
. The conveniences of the function syntax are a big deal for many people (especially coffeescript users and those who are strongly anti-JSX) so we don’t want to break anybody, but we would like to migrate them from the core React API.
So the proposal would be a new package which just exports the exact set of things that React.DOM
currently makes available. It would require some small changes to your code and a new package dependency, but is otherwise identical. Here’s what the change might look like.
// before
{div, span} = React.DOM
// after
{div, span} = require('react-some-other-package');
Issue Analytics
- State:
- Created 8 years ago
- Reactions:25
- Comments:27 (19 by maintainers)
Is there any reason to have these functions at all, vs JSX compiling to plain objects? It could be more user-friendly for the hand-written cases as well, and no need to
import 'react'
all the time or add it as a dep for many components.I don’t have full context on this so I can’t give a good reply. Here’s what I know about this:
createElement
that relies on global state about the currently executingrender()
method. I think the plan is to get rid of it (#6350) but that would mean deprecating string refs. Until_owner
is gone we can’t generate objects all the time without screwing up string refs.propTypes
validation or useful developer warnings.