Câu hỏi phỏng vấn Reactjs
Câu hỏi

What are props in React?

Câu trả lời

In React, "props" is short for "properties." They are a core concept in React that allows data to be passed from one component to another, specifically from parent components to child components. This mechanism is essential for creating dynamic and interactive user interfaces in React applications.

Props are read-only, meaning that a component can only read the props passed to it by its parent component; it cannot modify them. This immutability helps prevent bugs and maintain a predictable flow of data within the application. The data passed as props can include values like strings, numbers, functions, arrays, and even other React components.

Here’s a simple example to illustrate how props work in React:

function Welcome(props) {
  return <h1>Hello, {props.name}!</h1>;
}

function App() {
  return <Welcome name="Alice" />;
}

In this example:

  • The Welcome component receives props, an object containing all the properties passed to it.
  • The App component renders the Welcome component and passes a name prop to it.
  • The Welcome component accesses the name prop and uses it within the returned JSX to dynamically generate a greeting message.

Props are fundamental to React component communication, allowing developers to create reusable and isolated UI components that can be configured with different data inputs[1][2]...

entry

entry

Gợi ý câu hỏi phỏng vấn

junior

What happens during the lifecycle of a React component?

senior

How to create Props Proxy for HOC component?

middle

What's the typical flow of data like in a React + Redux app?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào