Please enable JavaScript.
Coggle requires JavaScript to display documents.
React (JSX (javascript extended, write JSX to describe what your UI should…
React
JSX
-
-
A transpiler like Babel converts that code into a bunch of React.createElement() calls. The React library then uses those React.createElement() calls to construct a tree-like structure of DOM elements (in case of React for Web) or Native views (in case of React Native) and keeps it in the memory
React then calculates how it can effectively mimic this tree in the memory of the UI displayed to the user. This process is known as reconciliation. After that calculation is done, React makes the changes to the actual UI on the screen
-
-
-
-
prevents injection attacks. By default, React DOM escapes any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that’s not explicitly written in your application. Everything is converted to a string before being rendered. This helps prevent XSS (cross-site-scripting) attacks.
-
-
Elements
-
-
-
-
Once you create an element, you can’t change its children or attributes
To render a React element into a root DOM node, pass both to ReactDOM.render(): ReactDOM.render(element, document.getElementById('root'));
-
-
-
function Welcome(props)
{return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;
ReactDOM.render(
element,
document.getElementById('root')
);
...in this code...
-
-
Our Welcome component returns a <h1>Hello, Sara</h1> element as the result.
React DOM efficiently updates the DOM to match <h1>Hello, Sara</h1>.
components
-
-
-
-
props
-
Most components can be customized when they are created, with different parameters. These creation parameters are called props
-
you should name props from the component’s own point of view rather than the context in which it is being used
-
-
-
events
-
With JSX you pass a function as the event handler, rather than a string
-
You cannot return false to prevent default behavior in React. You must call preventDefault explicitly.
When using React you should generally not need to call addEventListener to add listeners to a DOM element after it is created. Instead, just provide a listener when the element is initially rendered
lifecycle
We want to activate some code whenever something is rendered to the DOM for the first time. This is called “mounting”
We also want to clear/ deactivate its activity whenever the DOM produced by the Clock is removed. This is called “unmounting”
lifecycle hooks
The componentDidMount() hook runs after the component output has been rendered to the DOM. This is a good place to set up a timer etc
-
-
doesn't separate technologies by putting html and logic in separate files. Instead separates concerns, by having things separated by components which contain everything
-