繁体   English   中英

如何正确导出一个 React 组件

[英]How to correctly export a react component

我做了以下代码,React 的新手,但它似乎并没有在这里出错:

// React 16.x code below
import React from 'react';

// Create the Label React component here

function Label(props){
    var c = "color:'" + props.color + "'";
    return <div style="{c}">{props.value}</div>
}

// Modify this function if you want to change the preview
// It will not be evaluated as part of the assessment
export function Preview() {
    return <Label value={'Solution'} color={'blue'} />;
    // ReactDOM.render()
}

// Do not change
export default Label;

在此处输入图像描述

style道具接受 object,请参阅相关文档

style 属性接受带有驼峰式属性的 JavaScript object 而不是 CSS 字符串。

function Label(props) {
  return <div style={{ color: props.color }}>{props.value}</div>;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM