How are props and state different?
How are props and state different?
In React Native, both props and state are essential concepts for managing data and controlling the behavior of components. However, they serve different purposes and have distinct characteristics. Here is a detailed comparison:
function ChildComponent(props) {
return <div>{props.message}</div>;
}
function ParentComponent() {
return <ChildComponent message="Hello, World!" />;
}
import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
function handleClick() {
setCount(count + 1);
...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào