acdlite / recompose

A React utility belt for function components and higher-order components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question]: Using stateUpdaterName of withState inside initialState

mb8z opened this issue · comments

commented

I have been using recompose for quite a while, and it is great. Today I encountered a problem that I do not know how to solve.

I have a prop called list passed to a component and I convert it to state using withState function:

withState('stateList', 'setStateList', ({ list }) => list)

I want my list te mapped before it becomes stateList, but this mapping would need an access to the setStateList function itself like:

list.map((item, index) => ({
   ...item,
  onItemResize: () => setStateList(/*an updated list here where one item has different width */),
}));

My question - is it possible to access stateUpdaterName function inside the initialState method (where I can access the component's props)?

add onResize in next hoc using withProps

commented

It must be too late for me that I did not get it myself... Thanks a lot!