craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

Fix: Updating props from the outside

Open ankri opened this issue 3 years ago • 5 comments

My attempt at fixing the bug described in #190

You can test it in the basic example

I found a solution but hit a dead end. With this fix the props of the components get updated. BUT the component now will be rendered twice. Once with the old props and immediately with the new props.

Maybe someone has an idea?

ankri avatar Feb 13 '21 09:02 ankri

Deploy preview for craftjs ready!

Built with commit b79e5e0b2cae71d39e11f936b72f8f13a9f96b03

https://deploy-preview-191--craftjs.netlify.app

netlify[bot] avatar Feb 13 '21 09:02 netlify[bot]

Something like this would be wonderful – it’s currently a bit of a pain to try and update a component with a global settings provider; for instance, trying to set some global colors and themes, we’ve had to place the hooks inside the blocks themselves. Ex; accessing useContext(PropertiesContext) within a Text as passing props to Text will only seed the block on the initial mount.

timc1 avatar Feb 27 '21 13:02 timc1

I'm not really sure this is the correct way going about this, this essentially results in any extra props getting automatically copy pasted into Craft state, which might result in a lot of accidental props ending up in the state, it also mixes craft state with react state and eliminates a single source of truth for whats being rendered. I think to update props like that they should be injected straight into the state, rather than passed down as a prop and picked up by effect.

matdru avatar Feb 27 '21 13:02 matdru

@matdru do you have a recommended solution for handling something like global colors? For instance, a number of User blocks that inherit from a certain value in a provider. Changes in the provider would effectively update the user blocks?

timc1 avatar Feb 27 '21 13:02 timc1

@ankri Is there any plans to merge this PR or fix this issue in a different way?

real-ashwin avatar Mar 18 '21 22:03 real-ashwin

Closing due to no time available

ankri avatar Feb 19 '24 08:02 ankri