i created a custom attribute with name “mediaItem
“.
attributes.js
const attributes = {
mediaItem: {
type: Object,
default: {
type: 'none',
attachment: 'scroll',
size: 'contain',
},
},
In my custom component i want to update this value.
I found this example:
So i created this in my component:
const [mediaDimensions, setMediaDimensions] = useState(mediaItem);
const updateImageObj = (key, value) => {
setMediaDimensions({ ...mediaDimensions, [key]: value });
};
Unfortunately, nothing happend. My console.log output the same data.
Next i tried this example:
const updateImageObj = (key, value) => {
// setMediaDimensions({ ...mediaDimensions, [key]: value });
let oldObject = mediaItem;
mediaItem[key] = value;
setAttributes({ image: oldObject });
// console.log(mediaItem);
};
In my console.log the attribute was updated but the “Update” Button still disabled and i have no opportunity to save my state.
What am I doing wrong when saving an object?