useCallback + useImperativeHandle methods

Open
#856 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, typescript

Research direction

Start by reproducing the issue with the provided React component using useCallback and useImperativeHandle, then compare it with the working inline-method variant. Trace the component-method extraction path and confirm the fix by producing a method entry for _myMethod with its description and return type.

Written by the indexing model from the issue text.

Description

bug

Methods in the following component is not recognised. It works if I remove the useCallback.

import React, {
  forwardRef,
  memo,
  useCallback,
  useImperativeHandle,
  useMemo,
  useRef,
} from 'react';

export const MyComponent =
memo(forwardRef((_, ref) => {

  const _myMethod = useCallback((argument:string) : number => {});
  //const _myMethod = (argument:string) : number => {};
  
  useImperativeHandle(
    ref,
    () => ({
        /** myMethod description */
        _myMethod,
    }),
    [],
  );

  return <div />;
}));

return

[
  {
    "description": "",
    "displayName": "MyComponent",
    "methods": []
  }
]
Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
3h 28m
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reactjs/react-docgen

All issues in reactjs/react-docgen

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.