0

I need to console.log response or data values inside use callback but I can't, same whenever I debug with dev tools I can't read the data. I need to understand why is not possible to read the data and to debug with devtools.

     const List = (props) => {
     const [list, setList] = useState([]);

     const fetch = useCallback(async () => {
      try {
      const response = await fetch(
      "https://react-movie-e18ec-default-rtdb.firebaseio.com/movies.json"
        );
      if (!response.ok) {
      throw new Error("Something went wrong!");
      } 
     console.log("response", response);

    const data = await response.json();
    setList(data);
    console.log("data", data);
    } catch (error) {}
    }, []);

   useEffect(() => {
   fetch();
    }, [fetch]);

 const items = list.map((item) => <Item key={item.id} item={item} />);
  console.log("items", list);
return (
  <Fragment>
  <div className={classes.list}> {items}</div>
</Fragment>
 );
 };
 export default List;
skyboyer
  • 22,209
  • 7
  • 57
  • 64

0 Answers0