I need to provide a sub component with an array of numbers from state - the array is defined by a provided total number (this.props.totalMarkerNumbers) prop (in string format) - i'm going astray with the syntax construct and wonder if anyone can please point me in the correct direction please?
Heres my code to create the array:
const ArrayCont = () => {
let i = 0;
let totalM = parseInt(this.props.totalMarkerNumbers, 10);
for (i = 0; i < totalM.length; i++) {
let no="''" + i +"''";
return(
{
label:no,
value:no
}
)
}
}
const Markers = () => {
let arrayCont =
return (
[{this.ArrayCont}]
)
}
This would be stored in state as:
class A_Log extends React.Component {
constructor(props) {
super(props);
this.state = {
markerArray:Markers,
};
}
basically if this.props.totalMarkerNumbersprovided '4' i'd want the array to be:
this.state.markerArray = [
{
label: '1',
value: '1',
},
{
label: '2',
value: '2',
},
{
label: '3',
value: '3',
},
{
label: '4',
value: '4',
},
];
theres probably a lot easier way to achieve this - any advice very welcome! Cheers.