informed icon indicating copy to clipboard operation
informed copied to clipboard

useArrayFieldItem hook.

Open behzadmehrabi opened this issue 3 years ago • 11 comments

Hi, I want to window my form using react-window, in order for this to work correctly, there is need to be either ArrayFieldItem component or useArrayFieldItem hook. so when react-window wants to render the rows. I will give that component as a row.

right now, there is the ArrayField.Items which maps the values by itself.

behzadmehrabi avatar Dec 13 '21 11:12 behzadmehrabi

I dont follow. Can you create example issue in a code sandbox.

joepuzzo avatar Dec 13 '21 17:12 joepuzzo

sorry I wasn't clear.

https://codesandbox.io/s/focused-rain-gq0be?file=/src/App.js

can you understand the problem from this code sandbox or I should make it more clear?

behzadmehrabi avatar Dec 13 '21 22:12 behzadmehrabi

I'm making another code sandbox using react-window instead of react-virtual as it has less boilerplate code.

behzadmehrabi avatar Dec 13 '21 22:12 behzadmehrabi

https://codesandbox.io/s/mystifying-feather-g1epx?file=/src/App.js

checkout this one.

behzadmehrabi avatar Dec 13 '21 23:12 behzadmehrabi

I dont think this will work at all... array field is designed to need ArrayField.Items ( it does v important things intenrally. And even if i were to spend time refactoring that logic to live in hook it would not work because it requires all items be rendered at same time...

joepuzzo avatar Dec 14 '21 02:12 joepuzzo

could you explain a bit why does it require all items to be rendered at the same time?

behzadmehrabi avatar Dec 14 '21 06:12 behzadmehrabi

Because things like delete and swap depend on it ( especially delete ). If u delete array[9] then array[90] becomes array[89]. Array fields are the most complex thing in this library. It would take complete redesign of how they work to support not rendering all at the same time.

joepuzzo avatar Dec 14 '21 06:12 joepuzzo

Also for various reasons. Initial values will NOT populate "values" until the field its associated with is rendered onto screen. This means if u rendered an array field with 100 items and never scrolled to 100. The values would never see half the items

joepuzzo avatar Dec 14 '21 06:12 joepuzzo

When you look at array fields in a closed room it starts off seeming simple. Then u add the fact that fields are desinged to clean up after themselves on unrender + the concept of relevance where things become irrelevant or relevant depending on other things and the problem complexity goes way up.

joepuzzo avatar Dec 14 '21 06:12 joepuzzo

Also for various reasons. Initial values will NOT populate "values" until the field its associated with is rendered onto screen. This means if u rendered an array field with 100 items and never scrolled to 100. The values would never see half the items

this one really isn't much of an issue, when the item is not rendered at all, that means the value hasn't been changed.

Because things like delete and swap depend on it ( especially delete ). If u delete array[9] then array[90] becomes array[89]. Array fields are the most complex thing in this library. It would take complete redesign of how they work to support not rendering all at the same time.

but yeah, this one is a big issue, swapping an item with the one that hasn't been rendered yet :x.

behzadmehrabi avatar Dec 18 '21 07:12 behzadmehrabi

btw, could you fix the issue of keys getting changed after each re-render?

behzadmehrabi avatar Dec 18 '21 08:12 behzadmehrabi