javascript - ReactJS(jsx) 传递参数

标签 javascript reactjs

我是 react 新手,我想知道为什么参数(a)需要与变量一起传递,例如a.amounta.date 。这背后的过程和理由是什么?

最佳答案

它的通用名称“props”(在您的组件中它是“a”)。

“Props”是一个对象,它具有传递给组件的所有属性。

例如;

<ExampleComponent isEnabled={true} isClickable={false} />

然后您可以通过两种方式访问​​组件中的这些属性;

1:获取 prop 变量并将其用作对象,就像在示例中所做的那样。 2:销毁组件中的对象以根据需要使用。

const ExampleComponent = ({isEnabled, isClickable}) => {
    return "<></>";
});

了解更多信息:

https://reactjs.org/docs/components-and-props.html

关于javascript - ReactJS(jsx) 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68631011/

相关文章:

reactjs - 应用栏菜单项未打开正确的子菜单

javascript - 如何避免错误 "Unknown prop <> on tag. Remove this prop from the element"?

javascript - Chrome 扩展程序 : How to send html form data to a php page upon button being clicked which redirects to said php page

javascript - Google Maps API v3 map.fitbounds(bounds) 设置 map 缩放不正确的问题

javascript - React 路由器不显示浏览器历史记录

reactjs - 无法使用 React-Konva 渲染内容

css - Webpack 和 PostCSS 单独设置

javascript - 从助手获取模板数据

javascript - OpenWeatherMap - map 仅显示莫斯科

reactjs - refs 与 onChange