reactjs / react.dev

The React documentation website
https://react.dev/
Creative Commons Attribution 4.0 International
11.06k stars 7.56k forks source link

Missing very important step in this documentation for JSX syntax #2687

Open amitshahc opened 4 years ago

amitshahc commented 4 years ago

When I was trying to follow this documentation: https://reactjs.org/docs/add-react-to-a-website.html#optional-try-react-with-jsx all worked fine until I replaced native JavaScript to JSX.

The missing step is to replace the line: ReactDOM.render(e(LikeButton), domContainer); with ReactDOM.render(<LikeButton />, domContainer);

RohitRathore1 commented 4 years ago

This example shows React without JSX. Adding JSX to a project doesn’t require complicated tools like a bundler or a development server. Essentially, adding JSX feels a lot like adding a CSS preprocessor. These two code snippets are equivalent. While JSX is completely optional, many people find it helpful for writing UI code — both with React and with other libraries. You can play with JSX using this online converter

ahmadrasyidsalim commented 4 years ago

https://gist.githubusercontent.com/gaearon/0b180827c190fe4fd98b4c7f570ea4a8/raw/b9157ce933c79a4559d2aa9ff3372668cce48de7/LikeButton.js

The same result if you write some code like this, just without state:

React.createElement('button', { onClick: () => alert('The button was clicked') }, 'Click me')