question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Remove React.DOM (dom component factories) API and release as new module

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Reactions:25
  • Comments:27 (19 by maintainers)

github_iconTop GitHub Comments

5reactions
tjcommented, Mar 26, 2016

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.

3reactions
gaearoncommented, Mar 27, 2016

I don’t have full context on this so I can’t give a good reply. Here’s what I know about this:

  • We still have a concept of “owner” which is a dynamic thing set by createElement that relies on global state about the currently executing render() 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.
  • We added a certain level of protection against XSS in user input in #4832 which tags every “safe” element coming from the code (as opposed to a user JSON) with a Symbol. These would be a bit of a pain to write by hand.
  • There is a Babel plugin that makes JSX output inline objects. However we only recommend it in production because it effectively bypasses any propTypes validation or useful developer warnings.
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactDOM – React
The react-dom package provides DOM-specific methods that can be used at the top level of your app and as an escape hatch to...
Read more >
React v16.0 – React Blog
We're excited to announce the release of React v16.0! Among the changes are some long-standing feature requests, including fragments, ...
Read more >
React v16.9.0 and the Roadmap Update
Today we are releasing React 16.9. It contains several new features, bugfixes, and new deprecation warnings to help prepare for a future ...
Read more >
React Top-Level API
React components let you split the UI into independent, reusable pieces, and think about each piece in isolation. React components can be defined...
Read more >
Design Principles - React
There is nothing “bad” about using state or lifecycle methods in components. Like any powerful feature, they should be used in moderation, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found