REECT本地:带有颜色参数的自定义组件
我正在进行练习,以学习在编码上学习反应的人。
我被告知“在React中,属性作为对象作为第一个参数的对象传递给我们的组件。您需要在自定义组件中添加此参数,并将颜色属性用作背景颜色。”
我需要将颜色作为参数传递给我的盒子自定义组件。这是我的代码:
export const Box = (color) => (
<View color={color} style={{ width: 100, height: 100, backgroundColor: this.props.color }} />
);
它给我带来了语法错误。 我还尝试了:
export const Box = (color) => (
<View style={{ width: 100, height: 100, backgroundColor: color }} />
);
但是我被告知“视图应该具有颜色属性设置的背景颜色。”。当我这样做时,这是一样的
export const Box = (color) => (
<View style={{ width: 100, height: 100, backgroundColor: {color} }} />
);
,但是在调用react和正确使用它们的变量时,我总是误会了……
如果您能帮助我,那就太好了!
谢谢
Im doing the exercises to learn react native on codecademy.
I am told "In React, properties are passed as objects on the first parameter to our components. You need to add this parameter in the custom component and use the color property as the background color."
I need to pass color as a parameter to my Box custom component. This is my code:
export const Box = (color) => (
<View color={color} style={{ width: 100, height: 100, backgroundColor: this.props.color }} />
);
It throws me a syntax error.
I also tried :
export const Box = (color) => (
<View style={{ width: 100, height: 100, backgroundColor: color }} />
);
But I am told "View should have a background color set by the color property.". It's the same when I do
export const Box = (color) => (
<View style={{ width: 100, height: 100, backgroundColor: {color} }} />
);
It's very basic but I'm always mistaken when it comes to calling variables in React and properly using them...
If you could help me that would be great!
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您可以得到这样的道具:
Basically, you can get props like this: