What are the types of data that control a component?
What are the types of data that control a component?
In React Native, there are two primary types of data that control a component: props and state.
// Parent Component
function App() {
const fruits = { name: "Mango", color: "Yellow" };
return (
<div className="App">
<Fruit fruits={fruits} />
</div>
);
}
// Child Component
function Fruit(props) {
return (
<div className="fruit">
<h1>List of Fruits</h1>
<p>Name: {props.fruits.name}</p>
<p>Color: {props.fruits.color}</p>
</div>
);
}
setState
method.class Form extends React.Component {
constructor(props) {
super(props);
this.state = { input: '' };
}
handleChangeInput = (text) => {
this.setState({ input: text });
}
render() {
const { input } = this.state;
return (
<...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào