Home > Mobile >  The given code using useselector is not fetching data
The given code using useselector is not fetching data

Time:04-26

Here in functional component useSelector is not working and not fetching any images.I have also attached my codesandbox link below.

Edit How to use redux in your react app with Axios (forked)

CodePudding user response:

users is empty when your components mount thats why its not rendering anything, the action is called in next line.

const [data,setData] = useState([])

useEffect(()=>{ setData(users) },[users])

replace below code

if (!data.length) return null;

replace map function too.

const userData = data.map((user) => {
return (
  <React.Fragment key={user.id}>
    <h6> {user.first_name} </h6>
    <p> {user.last_name} </p>
    <p> {user.email}</p>
    <p>
      <img key={user.avatar} src={user.avatar} alt="avatar" />
    </p>
    </React.Fragment>
  );
});
  • Related