score:2
Just pass it as a prop in your map:
<Todo item={todo} key={todo.id} />
Then in your Todo component, you can grab the data:
<div>
<div>Title: {this.props.item.title}</div>
</div>
EDIT: Added the key as pointed out by Richard Fazzi.
score:2
Well, I'm learning react too and I have this to say to you:
Every list
must have a key, like this:
const menu = this.props.dishes.map((dish) => {
return (
<div key={dish.id} className="col-12 mt-5">
<Media tag="li">
<Media left middle>
<Media object src={dish.image} alt={dish.name}/>
</Media>
<Media body className="ml-5">
<Media heading>{dish.name}</Media>
<p>{dish.description}</p>
</Media>
</Media>
</div>
);
});
And I really think you should use a list.
The other thing I think you should do is to create a variable with the returned value from the map, then you can return that, eaxmple:
return (
<div className="container">
<div className="row">
<Media list>
{ menu }
</Media>
</div>
</div>
);
Hope it helps
score:2
If you want to pass that value to Todo you just pass it like you did with TodoList
:
In TodoList.jsx:
<Todo title={todo.title} />
and in Todo.jsx:
const { title } = this.props;
<p> Title: { title } </p>
Or you can pass the whole object:
<Todo todo={todo} />
const { title } = this.props.todo;
<p> Title: { title } </p>
Source: stackoverflow.com
Related Query
- How do I pass a value from an array defined in state into a component which beholds a component?
- React/Mobx: How to pass single item from a mapped array into another component and retrieve only the item associated with the value clicked
- how to pass props into component from route array in react
- How to check and return value of state object array and use that to identify which object to take data from
- How to access value based on index from array defined in state ReactJS
- How to pass value of state variable from one component to a sibling component?
- How do I take an array of objects from state and push a specific value of the objects into a new array
- How to properly pass an array from a parent React class component state to a child component written with hooks?
- How to pass value to props from component and set state
- How to pass state values from a component into another child component that contains param settings?
- how can i pass an input value from component to a state of a classe on react?
- How to pass a state value from one component to another component at the same level
- How to pass values from a component into Formik multi-step form wizard?
- How to pass value from parent component to child component (react)
- How to use useEffect hook properly with array dependency. I passed state from redux store and still my component renders infinitely
- React Final Form. How to set field value from component state
- How to pass input value from child to parent component react
- React.js how to pass in index as prop to child component from this.props array
- How to update state of a component with value from reducer state in react-redux?
- How to pass value from a child functional component to parent class component?
- React: How to pass State value to another component and use it to render a component
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How to make React.js fetch data from api as state and pass this state data from its parent to child component
- How to pass an Array from Child component to Parent component in react I know how to pass from parent t
- How to create array from state value and setstate after removing duplicates in reactjs
- How to update the correct state value in a parent component that gets its value from a child component using hooks in react?
- How to pass a value for useState hook from another component in ReactJS?
- How to pass data from a component into getServerSideProps
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- How to pass state from parent Component to child component in route (react-route-dom) reactjs
More Query from same tag
- Html selector returns an html collection and I don't know how to get to the element I need to make changes on
- react set state callback correct way to pass an argument
- styled components inheritance not working
- Function call and pass value in the same OnClick - React
- Can't insert into array reactjs
- React doesn't update data for loops
- Background Image not showing on build React
- chartjs-plugin-zoom not working with my React project
- ReactDOM.render doesn't work in getUserConfirmation
- How to structure a React app to pass values returned from a child's function
- Set ID's If Found in Array in React
- Reactjs style component with document.getElementById
- react cannot set property of props of undefined
- Jest/Enzyme testing: expect.toContain(img)
- eslint errors on .js files
- How to use Zomato API with React JS
- React Material UI OutlinedInput does not display error message
- React Redux: Testing mapStateToProps and mapDispatchToProps with Enzyme/Jest
- Switching Reactstrap NavItem programmatically
- Using the map function, show map elements that each have an image
- Axios does not catch and send data to client side
- react-map-gl: uncaught ReferenceError: _typeof is not defined
- Getting TypeError: d is undefined for d3 pie chart in React
- Required prop `visibleTodos[0].text` was not specified in `App`
- Render array of objects from Redux store as React components
- Infinity Loop with promises and state variables in ReactJs
- how to pass data between routes in react
- Submit button in a form works after the second click. ReactJS
- UseEffect still runs even if fetch data doesnt change
- How do I make a mailto that goes to link with email inside of it