I have a code using 'array of objects' that showing employees with details. I want to upload their images also. So where do I need to keep images(their path) in my ReactApp or I can upload from laptop's hard drive directly. What will be the code to upload an image for every single employee.
Here is my code below:
import React from "react";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
term: "",
names: [
{ name: "Deepak", age: 25, profile: "Developer" },
{ name: "Deepika", age: 24, profile: "Designer" },
{ name: "Deepinder", age: 22, profile: "Tester" }
],
filteredData: [{}]
};
}
render() {
let terms = "";
if (this.state.term) {
terms = this.state.term.toLowerCase();
}
return (
<div className="App">
<label>Search Employee: </label>
<input
type="text"
value={this.state.term}
id="searchEmp"
placeholder="Enter Name"
onChange={(event) => {
if (event.target.value.indexOf(" ") > -1) {
alert("Please don\'t enter space.");
this.setState({ term: "" });
return;
}
this.setState({ term: event.target.value });
}}
/>
<br />
<br />
{this.state.names &&
this.state.names
.filter((x) => x.name.toLowerCase().startsWith(terms))
.map((item) => {
return (
<div className="data-body">
<div>Name = {item.name}</div>
<div>Job Profile = {item.job_profile}</div>
<div>Description = {item.description}</div>
<input type="button" id="button" value="Delete"/>
<div>{<br></br>}</div>
</div>
);
})}
</div>
);
}
}
export default App;