Now?, We have learned how to use React To create elements and render elements, I also have a preliminary understanding of the syntax of the method of creating elements JSX. Open it in a browser, You will find that the elements on the page are not rendered correctlyĪnd the console outputs an error : Uncaught Synta圎rror: Unexpected token 'Īnd will script label ( To include JSX The grammatical script) Of type Attribute to :text/babel ![]() ReactDOM.render(div, document.querySelector("#root")) We will createElement Rewrite the created element to JSX But we write more simply and intuitively JSX First experience children) Method to create React Elements. In fact, Every JSX The element is a syntax sugar, They will eventually call React.createElement(component, props. It is called JSX, yes JavaScript Grammar extension of This tag syntax is neither string nor HTML For the first time react, It's too simple It can be written like this : const h1 = Hello,React! Ĭonst p = For the first time react, It's too simple We need to use ReactDOM Provided API : ReactDOM.render() ReactDOM.render("Hello, React!", document.getElementById("root"), () =>, h1) Ĭonst section = React.createElement("section", null, p) Ĭonst div = React.createElement("div", null, header, section) Now use React To render this title to the page If we want to add a text to this root element, such as : Hello,React!, We can do that : Then we add a root element to the interface : You can see that there are two objects, And there are many ways, Don't delve into every method for the time being React First experienceįirst of all we have html Introduction in :react.js react-dom.js Īt present, our code is written in html in, So it's all through script Tags are introduced into these two libraries ( I will not repeat it later ) Example 4-16 Basic HTML page .React and ReactDOM What is it? : console.log(React) If you use one Tags introduced react-dom, All the top floors API Can be in the overall situation ReactDOM On the callįirst look at it. If you use Tag to load React, You can use the React Global variable object to get React The top floor of API React yes React The entrance to the library. We can do it through the official CDN Link introduction react.js and react-dom.js These two libraries, Thus in HTML Use in
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |