score:1
the problem is that you are mapping over the props object, not the userlist
.
try to do the following:
const userlist = (props) => {
return (
<div>
<div id='home-header'>
<h1>devshelp</h1>
</div>
<div id='userlist'>
// use props.users.map instead of props.map
{props.users.map((user) => {
return (
<div classname='user'>
<h3>{user.username}</h3>
</div>
)
})}
</div>
</div>
)}
export default userlist;
and at home
component change the props of userlist to users
, just to avoid confusion
<userlist users={userlist}/>
score:2
i wouldn't name props for a component "props", really:
<userlist props={userlist}/>
if you really want to, then at least inside userlist, you would need to refer to the props object:
props.props.map...
name your props to something that make sense to you, like for example "users". then call props.users.map(user => {...})
a react component can take many props. when you want to access them inside the component, you need to do so by name. in your case, you defined userlist like this:
function userlist(props){...}
in this case, all props would have to be accessed via the props object. you defined a props
value inside this object when you called <userlist props={userlist]} />
personally, i always destructure props when i define a new component, like this:
function userlist({users}) {...}
as a side note, your code would have worked if you had destructured the props object: function userlist({props}) {...}
this would be the smallest change you could do to make the code work, i guess. but again, i would not use "props" as a name for a prop.
Source: stackoverflow.com
Related Query
- How can I make useEffect not return the initial value? I keep getting empty array when I'm trying to pass an array of objects into a component
- How can you check if there is an existing value in the array and not add it another time if so?
- React.js - How can I keep the value in inputnumber and make changes on it?
- How can I get the updated value only from a useeffect without it first returning the initial value null?
- How can i check if two state array shared the same value of not in React
- useState hook can only set one object at the time and return the other object of the same array to initial state
- How can I make the edit-mode field type of one material-table column dependent upon the value of another column, without affecting other rows?
- In Redux Form, how can I set the initial value of the checked property of a checkbox?
- Redux Toolkit w/ TypeScript: how can I properly type the return value from an async thunk
- How can I use an empty array declared on React's initial state?
- How can I export the type of an Action creators return value using Flow?
- How can I check the return value of dispatch in redux hook
- How can change the clone of an array and not change the original array in reactjs
- React-Hook Form with useFieldArray: TextField value does not show up in the console. How can I fix it?
- How do I fix a React TypeScript error with the return value of useHotkeys hook not matching the type of the div element ref prop
- How can I change the array key value before passing to the state in react?
- How can I return response.data if its an Object, not an array? map doesnt work with the code I have below
- How can I make the text area empty after I click the submit button?
- How can I get the daterange picker to return the value
- How i can filter through an Array and return the correct property?
- How to set the initial value of useState with the value of another state set in a useEffect hook?
- React - How to use the current state value as a variable so i can set as a index inside an array
- How do I iterate over an array of objects match a common element from another array and return the key value for "name"
- How can I change the value of an object in an array in react redux when the action is called?
- How can i use useReducer to assign initial state after calling custom Datafetch hook? I keep getting null
- Why does useCallback with an empty dependency array not return the same function?
- React: same component reappearing multiple times in the app, how can I make sure that all states are captured accurately and not just the last?
- React: How do I prevent the usage of useRef and useState to keep track of a same value in order to prevent useEffect from triggering?
- How can i can change the value of a variable with if/else to return certain div in react
- How can we compare each element array and show the element based on the value
More Query from same tag
- Remove empty items from my array and remove selected item when checkbox checked in react
- Specifying '!important' for CSS 'opacity'
- Tree data table with fixed (affix) parent rows
- propTypes should be a func console warning when passing in array of icons
- How generate dynamic DOM element in React
- Firebase onAuthStateChange() not working, still being redirected to login page on refresh
- Icons in react-table
- Change src path backgroundImage from url to folder CSS ReactJS
- Why is state.map(foo => <>{foo}</>) not displaying anything?
- React/Redux changing values in module (not in component)
- FormattedTime component throwing error when mounted in unit test
- How to pass a prop with an event handler function in React?
- how do i go to another page in function react js
- Seeing Blank page After refresh in nested routes in React Router
- How to get scrollPosition using getSnapshotBeforeUpdate() in React Js?
- Show first array element - ReactJS
- TypeError: symbol is not a function
- Why is there no `keyCode` value on the synthetic event in react using Semantic UI's Search component?
- Importing stateless functional components with styles in Reactjs
- React, use it to diff an object
- How would you make a button with CSS to not be clickable outside the button?
- Socket IO - server not connecting with my react client
- The margin on my cssmodules file doesn't work
- Session undefined in client side although available in server side in NextAuth.js v4 beta
- React: how to lift props up to parent component?
- react js display loading on button on submit
- create-react-class without npm using require and npm in React 16
- Display emoji object to text field or textarea in React
- Pass value of child component to parent component in React
- Import external JS library and use it inside React component