Clarify ReactDOM.render usage (#34682)

* Clarify ReactDOM.render usage

demo code misleads campers into thinking that the second arg for ReactDOM.render is a string

* Update index.md
This commit is contained in:
Jason Yung
2019-02-08 10:53:38 -05:00
committed by Randell Dawson
parent 76de5d0f50
commit bff8e37049

View File

@ -20,13 +20,14 @@ class TypesOfVehicles extends React.Component {
); );
} }
} }
ReactDOM.render(<TypesOfVehicles />,'node-id') ReactDOM.render(<TypesOfVehicles />, document.getElementById('node-id'))
``` ```
The ReactDOM.render syntax may be a little tricky, you need to use the triangle brackets when passing in a Class Component. Also the two subcomponents are declared behind the scenes, which may be confusing if you are used to all the variables being defined in the code editor and visible in front of you. The ReactDOM.render syntax may be a little tricky, you need to use the triangle brackets when passing in a Class Component. Also the two subcomponents are declared behind the scenes, which may be confusing if you are used to all the variables being defined in the code editor and visible in front of you.
## Hint ### Hint
- use document.getElementById('id') to get target node - use `document.getElementById('node-id')` to get target node whose id has the value 'node-id'
## Relevant Link ### Relevant Link
- [Rendering Elements](https://reactjs.org/docs/rendering-elements.html) - [Rendering Elements](https://reactjs.org/docs/rendering-elements.html)
## Solution ## Solution