recompose icon indicating copy to clipboard operation
recompose copied to clipboard

Getting an error server side rendering a withState component

Open abhiaiyer91 opened this issue 8 years ago • 5 comments

Hello!

I have a component that uses withState like so:

withState('item', 'setItem', ({ val }) => {
  return val;
})

Having upgraded to recompose 0.26.0 and React 16.2.0, i'm getting an error here

https://github.com/acdlite/recompose/blob/master/src/packages/recompose/withState.js#L21

Where my app is destructuring stateValue, but in the case I'm experiencing prevState is null!

does React guarantee prevState as an object?

Any ideas?

abhiaiyer91 avatar Dec 28 '17 21:12 abhiaiyer91

@abhiaiyer91 are you sure you're passing correct props for the component? and it's not getting null for first render?

pokorson avatar Jan 04 '18 20:01 pokorson

Real example? As stateValue is always defined for state https://github.com/acdlite/recompose/blob/master/src/packages/recompose/withState.js#L12-L13

istarkov avatar Jan 04 '18 20:01 istarkov

Getting the same error on server-rendering with after.js

panayi avatar Mar 14 '18 20:03 panayi

@panayi can you provide some example code to reproduce the issue?

wuct avatar Mar 19 '18 15:03 wuct

Hi, i'm want to ask is there a way that does not cause errors to use withState more than 1 time? Screen Shot 2020-06-05 at 17 28 36 and can you provide an example? thankyou

paulussimanjuntak avatar Jun 05 '20 09:06 paulussimanjuntak