函数组件可以通过 Props 来传递值。在函数组件中,可以通过参数的形式接收 Props,然后在组件中使用这些 Props。

例如:

function MyComponent(props) { 
  return (
    <div>
      <h1>{props.title}</h1>
      <p>{props.content}</p>
    </div>
  );
}

function App() { 
  return (
    <MyComponent title='Hello World' content='This is a sample content.' />
  );
}

在上面的代码中,App 组件通过 Props 向 MyComponent 组件传递了两个值,分别是 title 和 content。MyComponent 组件通过 Props 接收这两个值,并在组件中使用它们。

React 函数组件传值:使用 Props 实现数据传递

原文地址: https://www.cveoy.top/t/topic/lVO9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录