FrontEnd/src/user/pages/Users.js
// Even if we are not log in, we can see the list of users and the places they shared
Even if we are not log in, we can see the list of users and the places they shared
Even if we are not log in we can see the list of users and the places they shared
function Users() {
	const [users, setUsers] = useState([]);
	useEffect(() => {
		const getUsers = async () => {
			const res = await fetch(`${URL}/api/users`);
			console.log(res);
			const users = await res.json();
			setUsers(users);
			console.log(users);
		};
		getUsers();
	}, []);
	return <UsersList items={users} />;
}
function Users ( ) { const [ users , setUsers ] = useState ( [ ] ) ; useEffect ( ( ) => { const getUsers = async ( ) => { const res = await fetch ( ` ${ URL } ` ) ; console . log ( res ) ; const users = await res . json ( ) ; setUsers ( users ) ; console . log ( users ) ; } ; getUsers ( ) ; } , [ ] ) ; return < UsersList items = { users } / > ; }
Even if we are not log in, we can see the list of users and the places they shared
Even if we are not log in we can see the list of users and the places they shared
// set the initial users to be an emtpy array // useEffect to wait for the backend(3001) and fetch the list of users // converting users data to json objects // set our emtpy array to be the list of users // [] means not depending on anything that changes to call the function again