/
function component
function component
note
In React, function components are a simpler way to write components that only contain a render
method and don’t have their own state. Instead of defining a class which extends React.Component
, we can write a function that takes props
as input and returns what should be rendered. Function components are less tedious to write than classes, and many components can be expressed this way.
The square class can be converted to:
function Square(props) {
return (
<button className="square" onClick={props.onClick}>
{props.value}
</button>
);
}
In actual fact, we can go further and use the fat arrow function
const Square = (props) => {
return (
<button className="square" onClick={props.onClick}>
{props.value}
</button>
);
}
, multiple selections available,
Related content
Basic Concepts
Basic Concepts
More like this
node_modules
node_modules
More like this
7.3/4-nested_routes
7.3/4-nested_routes
More like this
18 - Intro to React - Exercise
18 - Intro to React - Exercise
More like this
ReactJS
ReactJS
More like this
Routes (navigation links)
Routes (navigation links)
More like this