I make custom SSR (nodeJS, ReactJS, Webpack) and i have trouble with React hooks.
When i try use hooks for example useState (her secound arguments), i'll get error "setGreetingsBlockData is not a function" on server console.
// Code from component
const { greetingsBlockData, setGreetingsBlockData } = useState({})
useEffect(() => {
fetch(
`https://adventuretimeapi.herokuapp.com/people`,
{ method: "GET" }
)
.then(res => res.json())
.then(data => setGreetingsBlockData(data))
}, [])
setGreetingsBlockData({test: 1})
How i can fix it?
CodePudding user response:
useState
returns an array, not an object
const [ greetingsBlockData, setGreetingsBlockData ] = useState({})