contentful / ui-extensions-sdk

A JavaScript library to develop custom apps for Contentful
https://www.contentful.com/developers/docs/extensibility/app-framework/
MIT License
126 stars 31 forks source link

Always initial state inside onConfigure function #314

Closed joeweale closed 4 years ago

joeweale commented 4 years ago

Hi,

I'm struggling to get a value from the components state inside the onconfigure handler. Everytime the state value is returned as its initial value not its current.

`export const Config = ({ sdk }: IProps) => { const [options, setOptions] = React.useState<Array>([]);

useEffect(() => { //state is being updated correcty console.log(options); }, [options]);

useEffect(() => { sdk.app.onConfigure(() => { //always initial value here console.log(options); }); setOptions([1, 2, 3]); }, []);

return

HELLO
; };`

Anybody able to advise what I should be doing differently?

Thanks

Joe

joeweale commented 4 years ago

Seems like with 3.12.1 I can work round it by settings the function on state change again.

https://github.com/contentful/ui-extensions-sdk/pull/283

Thanks