Skip to content

Example throws errors in create-react-app typescript template #1

Description

@harrisonturton

Hello!

This looks like an incredibly useful little package, but I can't seem to get it working.

I ran npx create-react-app use-multiple-refs --template typescript projects and tried the example. Specifically this:

import React, { useEffect } from "react";
import useDynamicRefs from "use-dynamic-refs";

const App: React.FC = () => {

	const [ getRef, setRef ] = useDynamicRefs();

	return (
		<>
			<input type="text" placeholder="Write..." ref={setRef("input")}/>
		</>
	);
};

export default App;

And I get these errors:

/Users/.../Documents/dev/multi-refs/src/App.tsx
TypeScript error in /Users/.../Documents/dev/multi-refs/src/App.tsx(10,46):
Type 'void | RefObject<unknown>' is not assignable to type 'string | ((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement> | null | undefined'.
  Type 'void' is not assignable to type 'string | ((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement> | null | undefined'.  TS2322

      8 | 	return (
      9 | 		<>
 > 10 | 			<input type="text" placeholder="Write..." ref={setRef("input")}/>
         | 			                                                                    ^
     11 | 		</>
     12 | 	);
     13 | };

Are there type annotations I'm missing? I had a look in your source, but couldn't quite figure it out.

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