Which of the following statements most accurately describes the difference between props and state in React?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng gồm hai ý: "props are used to pass data from a parent component to a child component, while state is used to manage the internal data of a component." và "state can be changed by the component itself, while props are read-only for the receiving component.". props là dữ liệu component cha truyền xuống con, phía con chỉ được đọc; state là dữ liệu nội bộ do chính component sở hữu, được đổi bằng this.setState hoặc hàm set của useState, và mỗi lần đổi sẽ khiến component render lại. "props allow the component to automatically update the displayed data based on user interactions." sai vì tương tác của người dùng được phản ánh bằng cách cập nhật state; props chỉ đổi khi component cha truyền xuống giá trị mới. "state should only be passed as a parameter between components and should not be used to store internal data." đảo ngược bản chất: state chính là nơi lưu dữ liệu nội bộ, còn khi muốn chia sẻ thì giá trị state được truyền xuống con dưới dạng props.
Cùng chương 6
Given the following Redux reducer and action in a React Native application, what will be the value of the state after dispatching the increment action? // Reducer const counterReducer = (state = { count: 0 }, action) => { switch (action.type) { case 'INCREMENT': return { ...state, count: state.count + 1 }; default: return state; } }; // Action const increment = () => ({ type: 'INCREMENT' });Có lời giảiCâu hỏiWhat is a key difference between useReducer and useState in React Native?Có lời giảiCâu hỏiWhich of the following is not an option to manage data throughout a React Native app?Có lời giảiCâu hỏiCả 13 câu của chủ đề13 câu