What type of component is represented by the code above?
4 phương ánCó giải thích
import React from 'react';
const Greeting = ({ name }) => {
return <h1>Hello, {name}!</h1>;
};
export default Greeting;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: "Functional component". Greeting là một hàm mũi tên nhận props, phân rã lấy name rồi trả về JSX thẻ h1 hiển thị lời chào, nên đây là function component (component dạng hàm). "Class component" cần cú pháp class kế thừa React.Component và có phương thức render(), mã trên không có. "Container component" là khái niệm theo vai trò: component lo lấy dữ liệu và logic rồi truyền xuống component trình bày; Greeting chỉ hiển thị dữ liệu được đưa vào nên không đóng vai đó. "Higher-order component" là một hàm nhận một component và trả về component mới đã được bọc thêm logic; Greeting nhận props chứ không nhận component nào.
Cùng phần 4
How can you ensure that a prop is passed as an array with at least one element?Có lời giảiCâu hỏiHow can you pass parameters to an event handler in React?Có lời giảiCâu hỏiWhich of the following is used to pass a function from a parent component to a child component?Có lời giảiCâu hỏiCả 40 câu của chủ đề40 câu