score:5
Effect's callback function should return void
, e.g.:
useEffect(() => { // callback; it returns void
console.log("Hi")
}, [])
Or
It should return a "cleanup" function of type () => void
, e.g.:
useEffect(() => {
console.log("Hi")
return () => { // cleanup function of type : () => void
console.log("Cleanup")
}
}, [])
You are getting the error because the cleanup function in your code is not of type () => void
, but of type () => Promise<void>
, e.g.:
Argument of type '() => () => Promise' is not assignable to parameter of type 'EffectCallback'. Type '() => Promise' is not assignable to type 'void | Destructor'.
useEffect(() => {
console.log("Hi")
return async () => { // WRONG
console.log("Cleanup")
}
}, [])
Hence, here is how you can refactor your "cleanup" function to fix it:
return () => { // Remove async from here
const clear = async () => { // Create a new async function: clear
// write your cleanup code here
};
clear() // Call the clear() function
};
score:3
The useEffect
callback should have return type void. So you can't return a Promise:
useEffect(() => {
document.querySelector('body').style['background-color'] = 'rgba(173, 232, 244,0.2)';
window.$crisp.push(['do', 'chat:hide']);
window.$crisp.push(['do', 'chat:show']);
document.querySelector('body').style['background-color'] = '#ffffff';
if (router.query.id) {
firebase.firestore()
.doc(`documents/${router.query.id}`)
.get()
.then((resDoc) => {
if (resDoc.exists) {
clearDocPrediction(router.query.id);
}
});
}
}, []);
Source: stackoverflow.com
Related Query
- 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>'
- getting error : Argument of type '() => () => boolean' is not assignable to parameter of type 'EffectCallback'
- Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<...'
- React with Typescript: Argument of type 'never[]' is not assignable to parameter of type 'StateProperties | (() => StateProperties)'
- Argument of type '"MY_EVENTS_LOAD"' is not assignable to parameter of type 'TakeableChannel<unknown>' in yeild takeLatest
- React TypeScript: Argument is not assignable to parameter of type 'never'
- Argument of type 'string' is not assignable to parameter of type '`${string}` | `${string}.${string}` | `${string}.${number}`'
- Argument of type '(dispatch: Dispatch) => void' is not assignable to parameter of type 'AnyAction'
- Argument of type partial is not assignable to parameter of type
- Argument of type 'Date | null' is not assignable to parameter of type 'SetStateAction<Date>'
- React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type
- Argument of type 'number' is not assignable to parameter of type 'never' in array.includes()
- Argument of type 'string | null' is not assignable to parameter of type 'ValueFn<SVGPathElement, Datum[], string | number | boolean | null>'
- Argument of type '() => () => Promise<void>' is not assignable to parameter of type 'EffectCallback'
- Getting an error Argument of type 'unknown' is not assignable to parameter of type 'Error | null'
- Redux Toolkit - Argument of type 'AsyncThunkAction<>' is not assignable to parameter of type 'AnyAction'
- React js Typescript Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'
- Argument of type 'Element[]' is not assignable to parameter of type 'Element'
- Redux - createStore. Argument of type is not assignable to parameter of type 'DeepPartial<any>'
- Argument of type 'AsyncThunkAction<any, void, {}>' is not assignable to parameter of type 'AnyAction'
- TS2345: Argument of type 'ReactNode' is not assignable to parameter of type 'ReactElement'
- Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'
- Argument of type 'typeof test' is not assignable to parameter of type 'Component<{ children?: ReactNode; } & DispatchProp<any>>'
- React onclick Argument of type 'EventTarget' is not assignable to parameter of type 'Node'
- TypeScript w/ React - Argument of type 'string' is not assignable to parameter of type 'keyof T'
- Argument of type 'Function' is not assignable to parameter of type 'ComponentType<never>'
More Query from same tag
- Make an integration between React and Laravel using CSRF token
- React Hooks useState() with Object TypeError: Cannot read property 'name' of undefined
- Material UI (Scrollspy) - React - use tabs to move through list and auto scroll to index
- react-hook-form Why does number input type ignore maxLength?
- Why is my state empty when updating on socket event?
- State exists but not a function error happens. this.setState is not a function
- Getting values from react-select component in react-hook-form?
- Send a JSON through Django REST Framework
- Linking Buttons and onClick
- useState values where useContext.Provider is defined
- Fetch data with redux saga
- TypeError: Cannot read properties of undefined (reading 'toLocaleString')
- pass "key" param to react component
- Uncaught type error: map function is not working for array variable
- How To Cache Images in React?
- Importing data from excel and displaying in a react component
- Redirect to an html page if the route isn't specified
- Redux Keep Session
- document.removeEventListner not removing event in reactjs
- Syntax error in IE11 with Webpack, Babel and React
- Recoil: parent state does not update when atomFamily is set
- Antd library: How to approach when trying to render an image?
- State is not upating in renderer() component
- ant-design select not styled properly
- Mocha will not recognise JSX
- Connect multiple inputs type number
- React: Multer image and data upload with using firebase function, node multer
- How to handle global state data into deeply nested components in Redux?
- React app needs reload after login to load data
- how to define a react router's IndexRoute when using dynamic routing