Reactjs | Sololearn: Learn to code for FREE!



import React from 'react'; import ReactDOM from 'react-dom'; What are "react" and "react-dom"? Where are they located? Can I use components within client side event? Check the click function Could it console log the element instead of the javascript object? function click() { //Executed in the client side console.log(<P/>) } class Button extends React.Component { render() { return <button onClick={click} id="button">button</button> } } class P extends React.Component { render() { return <p>Paragraph</p> } } ReactDOM.render(<Button/>, document.getElementById("root"))

3/22/2020 6:04:56 PM

Toni Isotalo

1 Answer

New Answer


You typically install react with a package manager like npm or yarn, and they work like any other module in that regard. (You can find the react files in the node_modules folder of your project) If you have node.js installed, you can run `npx create-react-app` in your terminal and it will set up everything for you. A component is just a class so you can use it on the client, yes. However, the JSX <Tag /> syntax is not proper javascript so you need to compile it down to regular js before the client can run it. You can do this with `babel` for example. Again, `create-react-app` will set up the build pipeline for you and you can just write react code and see live changes in your browser.