In this first example, you can see the use of the h1 element. You use the wrappers via the React.createElement function. In your applications, you’ll end up creating your custom components, but to get you off the ground, React provides wrappers around HTML DOM elements. You build your UI using components and you combine these components in any way you see fit. Next, there is the concept of components. You can, in fact, create React apps and render them in different environments outside the browser-for example in canvas, or natively in Android or iOS. ReactDOM is responsible for rendering the app in the browser. It has only a handful of methods, render() being the most useful. The API is intentionally minimal, so there are not a lot of method names to remember. All of the APIs available to you are accessible via this object. There are a few points of interest in the code that made your first app work.įirst, you see the use of the React object. However, having them locally makes it possible to learn anywhere and without an internet connection. You don’t have to download the libraries you can use them directly from. Note that React doesn’t impose any directory structure you’re free to move to a different directory or rename react.js however you see fit. $ curl -L > ~/reactbook/react/react-dom.js You can grab the latest 17.* versions of the two from the host, like so: Next, you need to add two files: one is React itself, the other is the ReactDOM add-on. Let’s go with the simplest one that doesn’t require any special tools and can get you learning and hacking away in no time.Ĭreate a folder for all the code in the book in a location where you’ll be able to find it.Ĭreate a /react folder to keep the React library code separate. First things first: you need to get a copy of the React library.
0 Comments
Leave a Reply. |