0
Follow
5
View

Why are my react hooks not getting called?

cqwrmjld 注册会员
2023-01-26 08:56

Looking at your code https://codesandbox.io/s/distracted-framework-g4eoy?file=/src/components/home/home.component.jsx

You don't need to use react useState. You are already storing state via redux. So use your state from redux:

Try replacing

const [state, setState] = useState({});

With

const state = store.getState();
dhf3328573 注册会员
2023-01-26 08:56

Your app was crashing. Fixed it and i can see useEffect being called

import React, { useEffect } from "react";
import { useState } from "react";
import "./home.css";
import { store } from "./home.store";

const Home = () => {
  const [state, setState] = useState({});

  console.log('###store', store)

  useEffect(() => {
    console.log('USE EFFECT CALLED')
    console.log('state 1', store.getState());
    setState(store.getState());
  }, []);

  console.log("state 2", state);

  console.log('state 3', store.getState());
  // setState(store.getState());
  console.log("state 4", state);

  return (
    
{state.section2?.map((section) => ( <>

Your Holiday Gift Guide

Gifts for everyone on your list (including you).

))}
); }; export default Home;

About the Author

Question Info

Publish Time
2023-01-26 08:56
Update Time
2023-01-26 08:56