score:7
Accepted answer
useStates
return an array, not an object...
So you can change
const { cities, setCities } = useState([]);
to
const [ cities, setCities ] = useState([]);
And it should work.
Source: stackoverflow.com
Related Query
- React Hooks - function inside function component passed as prop can't access state
- React Hooks Error: Hooks can only be called inside the body of a function component
- Function inside functional component in React hooks - Performance
- Using react hooks inside render prop function
- React Native : Access Component state inside a static function
- React + Antd + Rollup Component Library "Error: Invalid hook call. Hooks can only be called inside of the body of a function component"
- React Hooks can only be called inside the body of a function component
- React 17.0.1: Invalid hook call. Hooks can only be called inside of the body of a function component
- Receiving error - Hooks can only be called inside of the body of a function component when implementing React Spring basic example
- export function inside react component or access state in same file outside of component
- React Hooks Mobx: invalid hook call. Hooks can only be called inside of the body of a function component
- How to type async function passed as prop to React component
- React router v4.2.2: using a string instead of function inside component prop of Route results in error
- How to pass function from FUNCTIONAL to CLASS component and access it outside of render( without prop ), using context in react js?
- React: Unable to access the parent component's function which is passed as prop to child component
- Access function argument inside function react hooks
- Cannot access props from function inside React Component
- react function undefined when passed to functional component as a prop
- Pass a default prop inside function component in react js
- React useHistory: Hooks can only be called inside the body of a function component
- How to access the passed prop array inside the child component
- React complains that hook is not used inside of a body function when my component is passed into another component to render
- React component throwing TypeScript error for function passed in as prop
- React Redux-Toolkit: Invalid hook call - Hooks can only be called inside of the body of a function component
- React call from class to functional component. Error: Invalid hook call. Hooks can only be called inside of the body of a function component
- React Hooks: Instantiating state hooks on validation Error: Invalid hook call. Hooks can only be called inside of the body of a function component
- Error with calling React Hooks inside of Function Component
- React Hooks + Mobx => Invalid hook call. Hooks can only be called inside of the body of a function component
- Function not being passed as prop to child component in React
- React - Invalid hook call. Hooks can only be called inside of the body of a function component
More Query from same tag
- Put the `response.data` value into the `setState[]` array
- JS/React How to prevent data from being fetched if URL doesn't exist?
- react/redux map function doesnt return the value
- Uncaught ReferenceError: 'dragLayer' is not defined
- Too much child component props, should i pass them using a dedicated class?
- How to import react-bootstrap classes globally in my react project?
- Reload react-table on event
- What does SS stand for in a React Component declaration?
- cant pass date and time to next screen react native
- Issue with background masking and react-particles-js 3.0
- How to Pass in Store as a prop
- VS Code jump to matching/closing tag
- How I filter the column in Antd
- How do I convert image type In React- webp to png or jpg?
- ReactJS updating a single object inside a state array
- React Apollo Error: No more mocked responses for the query: mutation
- Assign variable from async method
- integrating 'react-thunk': 'cannot call a class as a function'
- How to get KeyCode from Android using event handlers?
- I need to set Fields to initial state after data added in table field onClick
- Accessing React component's props
- getFieldDecorator rules for password to contain lower case upper case letters and numbers?
- Best practice to handle errors in Redux and React
- Loop a shortened video html tag
- How to use useReducer instead of useState?
- Uncaught TypeError: Object.values is not a function
- Apollo MockedProvider not returning expected data
- React.js set CSS attribute (similar to setState)
- How to stop custom modal from expanding past the screen
- How to use Material UI "Progress Indicator" between two set dates?