score:5
Accepted answer
if you check thoroughly your statevariable<t>
type you may notice that setvalue
field of that type has signature:
setvalue: (value: t) => void
while you're trying to feed it instead of a value of type t
the value (function) of type: (prevstate: t) => t
.
to match your function implementation the type statevariable
should be defined as:
interface statevariable<t> {
value: t;
setvalue: (cb: (value: t) => t) => void;
}
react exposes special helper types for typing usestate
dispatch functions: dispatch<setstateaction<t>>
so you may write it also as:
import { dispatch, setstateaction } from 'react'
interface statevariable<t> {
value: t
setvalue: dispatch<setstateaction<t>>
}
Source: stackoverflow.com
Related Query
- PrevState typing in TypeScript
- Strongly typing the react-redux connect with typescript
- styled-system props typing with TypeScript
- Typing a React component that clones its children to add extra props in TypeScript
- React and typescript with webpack typing issue
- Typing redux forms v7 with TypeScript and React
- TypeScript typing issue (marginally related to (P)React)
- Typescript - IntrinsicAttributes and children type issues when typing React components
- Typing generator functions in Redux-Saga with Typescript
- Typescript how to mix dynamic([key: type]: type) and static typing for an interface
- Typing out react-transition-group handlers in TypeScript
- Correct Typing for HigherOrderComponents with recompose and typescript
- use PrevState in useState hook in React typescript
- Typing a function identically to another function with Typescript
- issue with typing an object Typescript error - no index signature
- TypeScript typing for dynamic react context
- React Typescript Function Component typing
- Typing Redux toolkit's store in TypeScript
- Typescript typing a reference for third party custom components (react-player)
- Typing Redux Store with Typescript
- Typing component state with typescript when using react hooks
- React typescript onClick event typing
- React + Typescript styled components themeProvider props typing issue
- Typescript stateless HOC react-redux injected props typing
- Component typing react typescript
- Typing a custom react-redux connect function in Typescript
- Redux Toolkit with TypeScript - typing RootState with an SSR framework like Gatsby
- Typescript React alias HOC (to use <Component.alias />) typing issues
- TypeScript will not let me use prevState in setState
- Typing a functional component react using typescript
More Query from same tag
- How to check which element is hovered using React 17.0.2
- react component out of the css grid
- Conflict between localStorage and actual value
- Fetch is still pending in react api call
- How can I update State in React using the React-Select Component and User Selection?
- Fill <object> svg using jss
- Redux-thunk "dispatch is not a function"
- Children of flex container nested inside another flex container not taking width well
- Socket.io is not connecting with client (react.js)
- Is there a way to handle input hidden value in onSubmit?
- React Private Routing through id
- react-full-page prevents my page from opening in a certain ID like http://localhost:3000/#someIdWhereIWantThePageToBeOpened
- p5js resizeCanvas is not a function on resize
- Redirect within a function (React)
- How do I update the default useSate value from a html input?
- displaying a result in render from a function in REACTJS
- How to detect overflow of React component without ReactDOM?
- React-router - How to pass data between pages in React?
- React, Leaflet - Hooks, setView, and useRef
- this.context.toggle is not a function
- In React, calling state twice, but second one always one step behind?
- Filtering an Array within an Array in React
- Making specific style only apply to TableCell in Table body
- Change react props within component as optimization
- create-react-app MaterialUI Error: Invalid hook call
- Warning when changing controlled input value in React
- Issue in React and SignalR where SignalR connection is not identified
- Setting the state with React + TypeScript
- eslint + jsconfig + nextjs module path aliases (absolue path import - @)
- connect counter with items in an array react hooks