Background
I am going to be filtering a table based on the values in a selection box. I am having trouble understanding state
and props
within react.js
. Once I pass the value in I can easily do the filtering but I am trying to do this the "react" way.
Question
How do I pass the value of SelectionBox
when it is selected or changed to TableDisplay
when the user selects one of the options?
Example
class SelectionBox extends React.Component {
render() {
return <div className="filter">
<label for="business">Filter by Status
<select id="business" name="business">
<option value="all">All Requests</option>
<option value="approved">Approved</option>
<option value="pending">Pending</option>
<option value="denied">Denied</option>
</select>
</label>
</div>;
}
}
class TableDisplay extends React.Component {
render() {
return <div className="wrapper">
<h1>Requests</h1>
<SelectionBox />
<div><table className="table">
<tr className="seperate"><td>Title</td><td>Status</td><td>Created</td><td>Updated</td><td>Delete</td></tr>
{Object.keys(requests).map(function(key) {
let styling = "bg-plain";
if (requests[key].status == "Approved") {
styling = "bg-success";
} else if (requests[key].status == "Denied") {
styling = "bg-danger";
}
return <tr className={styling}>
<td>{requests[key].title}</td>
<td>{requests[key].status}</td>
<td>{requests[key].created_at.slice(0, 10)}</td>
<td>{requests[key].updated_at.slice(0, 10)}</td>
<td><a href="">Delete</a></td>
</tr>;
})}
</table>
</div></div>;
}
}
Research
From reading I think what I need to implement here is,
Inside SelectionBox
constructor(props) {
super(props);
this.state = {
// Something referring to the state of the select box here
};
};
Then access props
from within TableDisplay
?