score:33
Accepted answer
The function of useEffect
(EffectCallback
type) should return void
or () => void | undefined
.
function useEffect(effect: EffectCallback, deps?: DependencyList): void;
type EffectCallback = () => (void | (() => void | undefined));
In your case, you returning void => boolean
:
// void => boolean
return () => (isMounted.current = false);
To fix it, add scope to the statement of the cleaning function:
const useIsMounted = () => {
const isMounted = React.useRef(false);
React.useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
return isMounted;
};
Source: stackoverflow.com
Related Query
- getting error : Argument of type '() => () => boolean' is not assignable to parameter of type 'EffectCallback'
- Getting an error Argument of type 'unknown' is not assignable to parameter of type 'Error | null'
- Argument of type 'string | null' is not assignable to parameter of type 'ValueFn<SVGPathElement, Datum[], string | number | boolean | null>'
- Using state and includes in React gives Argument of type 'number' is not assignable to parameter of type 'never' error
- getting error : void' is not assignable to type 'FC<IPickWinnerProps>' in react js
- Error argument of type 'Item' is not assignable to parameter of type 'string'. TS2345
- getting error :Type '[null, Dispatch<SetStateAction<null>>]' is not assignable to type in typescript react
- Getting a Typescript error saying, some type is not assignable to parameter of type 'ReducerWithoutAction<any>'?
- Getting error "Argument of type 'typeof Header' is not assignable to parameter of type 'ComponentType...' or 'StatelesComponent'..."
- Argument of type is not assignable to parameter of type Typescript Error
- Getting Error: Argument of type 'number' is not assignable to parameter of type 'string'
- getting error type any is not assignable to type never
- Trying to use setType and getting Argument of type 'any[]' is not assignable to parameter of type 'SetStateAction<undefined>'
- Why does TS give the following error in my case: Argument of type 'number' is not assignable to parameter of type 'never'?
- How to fix the error argument of type string or undefined is not assignable to parameter of type string using typescript and react?
- Typescript error on React Component: Argument of type 'Element' is not assignable to parameter of type
- TypeScript error Argument of type is not assignable to parameter of type Appstate despite having all necessary types included
- TypeScript Error (TS2345) argument of type Person | undefined is not assignable to paramater of type Person
- Argument of type (key: string, id: string, pagination: number) => Promise<void> is not assignable to parameter of type Boolean
- Typescript returning error Argument of type is not assignable but it seems like it is confusing one function for another
- TypeScript Error Argument of type '{}' is not assignable to parameter of type 'Variable Y'
- How to fix error "argument of type (open: any) => boolean is not assignable to parameter of type boolean" using react and typescript?
- How to fix error argument of type undefined is not assignable to parameter of type 'string or () => string usng typescript and react?
- How to mock axios call in test? Keep getting argument of type is not assignable to parameter of type
- React Typescript - Argument of type is not assignable to parameter of type
- Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element'. Type 'null' is not assignable to type 'Element'.ts(2345)
- Argument of type 'unknown' is not assignable to parameter of type '{}'
- Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>
- react usestate hooks error: argument of type 'yyy' is not assignable to parameter of type 'setstateaction<xx>'
- Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<...'
More Query from same tag
- Sending state data down to parent component
- How to ensure successful updating data before get them
- Selecting a json key-value pair dynamically in React
- Best way to run a function when page refresh
- Express/mssql login form throws "ReferenceError:"" is not defined"
- How to pass props to route without causing component to mount twice?
- Setting Background image via JSON Schema in React Inline
- Setting a state in react but keep getting an error 'state' is assigned a value but never used no-unused-vars
- laravel broadcasting - client receives one response several times
- How to use this.executeAction("someAction") in function based Component?
- React Semantic-UI: Dropdown.Menu / Problem
- Reactstrap - how to create dropdown inside a Form Group
- How to update component's state after redirect?
- Toggle visibility in Antd form
- How do I get the updated state from Redux using useEffect
- Step by step dispatch in react redux, is it right?
- Reactjs how to use useEffect to handle many changes to useState
- Typescript: Property 'name' does not exist on type 'Employee[]'
- Nock not working with axios get at actions async test
- React, Single Page Apps, and the Browser's back button
- Confused about hosting a dynamic app with custom api with express
- React Uncaught TypeError: transcript.Transcription.map is not a function
- how to get cookie in react passed from express js api (MERN stack)
- React api request gives me undefined even when using state
- How to add infinite scroll in react redux app
- Meteor React Komposer: Execute Component Constructor AFTER ready subscription
- How to setup mocha to run tests in a Gatsby repo
- Display response JSON data from laravel validate
- Reactjs application Azure deployment getting failed
- Lexical error on line 1: Unrecognized text. Erroneous area: 1: 0 - none. Heroku, Scss, React