我试图在React组件中设置一个图像加载器,以在加载后显示/渲染它(仅客户端,没有http请求)。图像作为对象加载,导致渲染错误:“对象作为React子代无效”
import React, { Component } from "react";
export default class extends Component {
state = {
selectedImage: null
}
onChange = (event) => {
this.setState({
selectedImage: event.target.files[0],
})
}
render() {
return (
<div>
<div>
{this.state.selectedImage && this.state.selectedImage}
</div>
<form onSubmit={this.onFormSubmit}>
<input type="file" name="someImage" accept="image/*" onChange={this.onChange} />
<button>Add This Car</button>
</form>
</div>
)
}
}
预期结果-加载的图像在屏幕上显示/渲染。实际结果-错误:“对象作为React子对象无效” ...
慕盖茨4494581
相关分类