score:26
Accepted answer
You need to provide the interfaces/type aliases so that TypeScript will know the typings of state
.
After creating the interface for state
, you will need to provide the interface as the generics for useState
.
To solve the 2nd issue, you will need to provide the key
props to each item of the <li>
element
interface StateProperties {
name: string;
age: number;
}
function App() {
const [state, setState] = useState<StateProperties[]>([]);
// do the rest
return (
<div className="App">
{state.map(({ name, age }) => {
return <li key={`${name}-${age}`}>{name}</li>; //FROM HERE ERROR IS COMING
})}
</div>
);
}
Source: stackoverflow.com
Related Query
- Argument of type 'File' is not assignable to parameter of type 'never'. React with TypeScript
- React Typescript - Argument of type is not assignable to parameter of type
- React with Typescript: Argument of type 'never[]' is not assignable to parameter of type 'StateProperties | (() => StateProperties)'
- React js Typescript Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'
- TypeScript w/ React - Argument of type 'string' is not assignable to parameter of type 'keyof T'
- Stateful Component with Typescript and react-redux: Argument of type 'typeof MyClass' is not assignable to parameter of type Component
- Typescript React type argument of type not assignable to parameter of type
- Typescript error on React Component: Argument of type 'Element' is not assignable to parameter of type
- How to fix React TypeScript error: Argument of type '""' is not assignable to parameter of type 'SetStateAction<undefined>'
- 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<...'
- React TypeScript: Argument is not assignable to parameter of type 'never'
- React with TypeScript - Type {...} is not assignable to type 'Readonly<S>'
- CombineReducers with Typescript returns error "Argument of type is not assignable to parameter of type 'ReducersMapObject'"
- React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type
- Creating reusable Button Component with React and Typescript with not assignable type error
- React onclick Argument of type 'EventTarget' is not assignable to parameter of type 'Node'
- Using state and includes in React gives Argument of type 'number' is not assignable to parameter of type 'never' error
- Argument of type 'never[]' is not assignable to parameter of type 'never' when declaring a type in Typescript
- Typescript Error: Argument of type 'NodeListOf<HTMLInputElement> | undefined' is not assignable to parameter of type 'Iterable<HTMLInputElement> ..."
- React Redux connect is not assignable to type '() => void' with typescript
- React with Typescript | Functional component | Type 'boolean' is not assignable to type 'ReactElement<any, any>'
- Typescript complaining about React useState setter `Argument of type 'Dispatch<SetStateAction<never[]>>' is not assignable to parameter of
- React and Typescript: Argument of type is not assignable to parameter of type 'EventListenerOrEventListenerObject'
- Using EmailJS in TypeScript for a contact form, Argument of type 'EventTarget' is not assignable to parameter of type... .ts(2345)
- TypeScript - Argument of type 'String' is not assignable to parameter of type 'string'
- Argument of type '(props: ITableProps) => JSX.Element' is not assignable to parameter of type ... - React HOC
- Argument of type is not assignable to parameter of type 'SetStateAction<never[]>'. in React
- TypeScript React Component with specific string value parameter is not assignable
- Argument of type is not assignable to parameter of type Typescript Error
More Query from same tag
- how to get field value on change for FormItem in antd
- Adobe React-Spectrum TextField error using refs
- Is nesting React Context Provider and consuming those with useContext a problem?
- React has detected a change in the order of Hooks --- When using Context within a Hook
- How to add elements in cytoscape graph from react component?
- Using useState of complex object not working as expected in ReactJS
- Updating a list of options in the child when updating the parent state
- Warning message using ant design dynamic form
- How to display nested json data in React in key and value pair form?
- create-react-app installs with reported NPM vulnerabilities, should I do something?
- how to map json data in dropdown list (Functional component)?
- How to change data in a cloned table?
- How do I prevent an entire list from re-rendering when state of one component changes?
- Redux has an array but cannot map the data
- Is it possible from the event interface, to check if the event.target has property checked?
- Updating state from child component to parent component
- How to resolve this error? I cant install this (@ramonak/react-excel) package for edit Imported Excel
- How to style material UI box component to overlay
- Toggle icon color upon button click using React Hooks
- ReactJS change background image dynamically?
- Remove React components that throw an error from a grid
- Recharts join disconnected lines
- React, refetch from api when item is added
- Triggering a React effect periodically
- How to start React JS application in background mode on linux?
- How to use Typescript Union Type in React PropTypes?
- React - hopefully simple formatting of a link
- How can I adjust my formula to continuously autofill the missing paramater?
- Route exact path="/" not working for react github
- componentWillReceiveProps do not fire