F
Filament15mo ago
sm

Add dehydrateStateUsing to Builder\Block

I have a builder that I'm using to store related data on a Form, adding a dehydrateStateUsing to the builder works, but I want to have each block manage it's own dehydrated state to keep things a little bit more modular.. but adding a dehydrateStateUsing to the Block doesn't seem to work (never gets called). I've also tried accessing ->blocks() and running getState() on them within the builder, but that doesn't trigger the dehydrateStateUsing callback either. The docs state that whenever getState() is called the dehydrateStateUsing is called.. but that doesn't seem to be the case for Blocks? Any pointers?
5 Replies
Patrick Boivin
Patrick Boivin15mo ago
I can confirm, dehydrateStateUsing() is called at the Builder level and for each field in a Block, but not fot the Block itself. I think it makes sense conceptually, if you think of a Block as a group of fields. I think the simplest option is probably to roll you own logic inside of the Builder's dehydrateStateUsing() to map each block's data to a transformer (custom class or method).
sm
smOP15mo ago
Was hoping I wouldn't have to do that, but so be it 🙂
Patrick Boivin
Patrick Boivin15mo ago
Could be an interesting PR if you have some time... just saying 😜
sm
smOP15mo ago
If PRd, I think this would have to apply to other "layout" components as well.. Don't think it makes sense to have a special case for Block.. I don't think dehydrateStateUsing works on Section, Group etc either (just tried) And if Block is basically a layout field, then atleast its consistent right now 🙂
awcodes
awcodes15mo ago
A layout component doesn’t have ‘state’
Want results from more Discord servers?
Add your server