score:1
Accepted answer
You need to pass it in the binding:
var Board = React.createClass({
//dungeon map available in this.props.board
render: function() {
return (
<table className="table">
{
this.props.board.map(function(item,index){
//loop through every element of the board array
//these are the rows
var row = index;
return (
<tr>
{
/** NOTICE rowIndex **/
item.map(function(rowIndex, item,index){
var position = [row, index]
//this does not work for row
//row from outer map loop not accessible
return (
<Cell value={item} position ={rowIndex}/>
)
/** NOTICE we pass the row's index to binding **/
}.bind(this, index))
}
</tr>
)
}.bind(this))
}
</table>
)
}
});
NOTE: The order matters. notice rowIndex
is first.
Source: stackoverflow.com
Related Query
- How to send the position on a board from a Board to a Cell component in React JS using nested array.map
- React & Formik : how to send back sucess or failure from sucess handler to the component
- How to send array of objects data from child component to parent component and store in the parent object using react hooks?
- Making an HTML string from a React component in background, how to use the string by dangerouslySetInnerHTML in another React component
- How to initialize the react functional component state from props
- How to pass the match when using render in Route component from react router (v4)
- How to update the state of a sibling component from another sibling or imported component in REACT
- How does React know the component is removed from the DOM?
- How do I sync state from the DOM to my React Component in an Isomorphic Application?
- how do I interpolate a Link component in Next-i18next / React i18next that changes position in the text
- How to prevent React from re-rendering the whole component
- Using React how do I toggle the visibility of a nested component from a container component?
- How to call a component function on other component, but from the other component ? React
- How do I manage state on a React component that can have state changed from the parent or from events upon it?
- How can I use react useContext , to show data from context, in the same component
- Send message from service woker to react component in some of the browser which donot support BroadcastChannel
- How do I pass in the variant property of the material-ui TextField from a wrapping React component
- React JS: How to send an event down the component tree?
- How to update parent state from child component in React + send a paramater
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How is an argument for a callback in React being passed from the child component to the parent component?
- How to send a fetch post request from react component to backend
- How to send data from react and use the request body in express, using Axios?
- how to get a Component variable from another component but their both in the same file React
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- How to send state from Child component to another component in React
- How to take the input from a react component and pass the length of the input to another react component
- How do I send data from child component to parent component in React
- How to update redux state using a react variable passed up to the component from a child
- How to stop the previous component from rendering when it is redirected to another component in react
More Query from same tag
- Invalid hook call trying to make an axios get request in react
- How can I access nested arrays in a data object to assign as prop values for a data-grid?
- Fetch Json data is not displayed
- Sending a csv from front-end to backend using axios
- Failed to set state for react functional component
- React after Delete I get "Unhandled Rejection (TypeError): this.state.products.filter is not a function"
- Link tag not working and direct to require page
- Reactjs - What is optimized way for multiple api calls?
- how to add event listener to determine what the coordinates inside a div is clicked?
- How would I be able to pass the product ID according to what product was selected?
- Referring to window size in React Material-UI makeStyles
- Unable to import sass files in new React application
- Change sort key for rendered mapped array in React
- How to prevent blank page in react on http errors
- In React, how to pass an element as a Prop and Render without wrapping an element around it?
- implement the onSnapshot function for getting realtime updates in reactjs code
- Calculate time ago / days ago from javascript dates that had to be converted to string
- Preview File before uploading in proper way.(React&Typescript)
- Typescript - forward and useref
- passport authentication works from postman but not with fetch()
- Advanced positioning and sizing of a react radio button group on top of an SVG
- Initialize React class/component on existing Website with attributes
- Creating controlled inputs with HOC in React
- React setState doesn't update
- App Service web app showing file structure instead of actual web apge
- GenericType in React.FC<Props<T>>
- How to access React from outside the App?
- Implement react-router PrivateRoute in Typescript project
- Filtering values from inside array
- How can I add live-reload to my nodejs server