I'm working on an application on for analyzing matrices (https://en.wikipedia.org/wiki/Matrix_(mathematics)) using techniques from linear algebra. I have all the functions created for doing the analysis/computation, but I'm having trouble figuring out how to set up a dynamically sized form of numerical inputs in react.
I have a couple idea on how to implement it (neither of which is working as I'd hoped). One being to use a container component called Matrix that instantiates a grouping of child Entry components that would be used for actually getting the input. The only problem is how to best iterate over those entries and get their individual values. Past that, figuring out how to best display them has also proven challenging.
The Array.prototype.map seems like a solid way after getting the right size matrix (using row and col values in the store's state) but the component organization is elusive. The rows and cols are currently obtained from the store and then passed in as props to the Matrix component.
render() {
let arr = [];
for (let i = 0; i < this.props.rows; i++) {
arr[i] = [];
for (let j = 0; j < this.props.cols; j++) {
arr[i][j] = `${i},${j}`;
}
}
var entries = arr.map((rows, i) => {
return rows.map((cols, j) => {
return <Entry id={`${i},${j}`} value={0}/>
});
});
console.log(arr);
console.log(entries);
return (
<div>
{entries}
</div>
);`
The end goal is to create a composite array of arrays with numbers inside that can then be added to the state via reducers already tested and created. The form of the matrix is: [[1,0],[0,1]] for a 2x2 matrix. So ultimately it would probably look and be formatted on the page as:
`<Entry id={"0,0"} /> <Entry id={"0,1"} />
<Entry id={"1,0"} /> <Entry id={"1,1"} />`
Which then could be translated into the above style matrix. Also, to be clear, each entry is its own input tag (technically using FormControl from react-bootstrap).