Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
can not get current props in useEffect

I use useEffect with parameter props.quizStep. But fn(keydown event listener function) cannot get current props.quizStep.

Why it cannot get current props?

Here is my code.

    const moveBirdKeyboard = React.useEffect(() => {
        console.log('moveBirdKeyboard props.quizStep', props.quizStep);
        let fn = (e: any) => {
            console.log('props.quizStep', props.quizStep);
            moveBirdEvent(e);
        }
        if(eventListener.current === false) {
            (window as any).addEventListener('keydown', _.throttle(fn,10)); //_.throttle(fn,1000));
            eventListener.current = true;
        } 
    }, [props.quizStep]);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You cannot assign the useEffect hook to a variable, as it says its a hook, not a property. Instead of that you need to create a function which properties can be attached to a hook.

A good example from the reactJS documentation:

function Example() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    document.title = `Clicked ${count} times`;
  });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!