React-dropzone 样式拖放区

React-dropzone style drop area

我是 reactjs 的新手, 尝试创建一个使用 react-dropzone 的组件。 我想知道,覆盖默认设置以设置拖放区域样式的最佳方法是什么。

到目前为止我有 inline style,但在我看来我没有做 'right' 事情。

<Row>
    <Jumbotron className="text-center">
        <h4>Create a manual call</h4>
        <Dropzone 
            className=""
            multiple={false}
            onDrop={this.onDrop}
            style={{"width" : "100%", "height" : "20%", "border" : "1px solid black"}}>
                <div>
                    Try dropping some files here, or click to select files to upload.
                </div>
        </Dropzone>
    </Jumbotron>
</Row>

有什么帮助或更好的建议吗?

谢谢!

你所做的一切都很好。如果您愿意,可以在添加到项目的 .css 文件中编写样式。给组件一个 className 并在项目的某处导入 css。

<Dropzone
  className="dropzone"
  multiple={false}
  onDrop={this.onDrop}>
  <div>
    Try dropping some files here, or click to select files to upload.
  </div>
</Dropzone>

/* styles.css */
.dropzone {
  width : 100%;
  height : 20%;
  border : 1px solid black;
}

有更多的库需要做 css-in-js 像 styled-components,但是没有 100% 正确的解决方案。

您可以像这样创建样式对象

const dropzoneStyle = {
    width  : "100%",
    height : "20%",
    border : "1px solid black"
};

像这样在jsx中使用变量

<Dropzone 
  className=""
  multiple={false}
  onDrop={this.onDrop}
  style={dropzoneStyle}
>
  <div>
       Try dropping some files here, or click to select files to upload.
  </div>
</Dropzone>