Skip to content

Invalid hook call #23

Description

@HuangHam

Hi! I am trying to use this package and I am following the doc:

import React, { useState, useEffect, useRef, useCallback} from "react";
import { useDelay } from 'react-use-precision-timer';
import styles from ".././index.css";
import { usePlayer} from "@empirica/core/player/classic/react";

export function Fixation({is_practice = false}) {
  const callback = useCallback(() => console.log('Boom'), []);
  // Will call once after 1000ms.
  const onceTimer = useDelay(1000, callback);

However I get this warning:

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

and error:

TypeError: Cannot read properties of null (reading 'useState')

I don't think the react versions are a problem:

npm ls react
dyat_v3@ /Users/hh7792/Desktop/Dyat/dyat_v3
└─┬ react-use-precision-timer@3.5.5
├─┬ react-dom@18.3.1
│ └── react@18.3.1 deduped
├─┬ react-sub-unsub@2.2.7
│ └── react@18.3.1 deduped
└── react@18.3.1

Anyone has any thoughts on what is going on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions