Here in functional component useSelector is not working and not fetching any images.I have also attached my codesandbox link below.
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>
);
});