How to modify array of object in Gutenberg (block/editor)?

Question

I want to create accordion plugin, my problem is that I do not know how to modify a state in array of object.

my state in block.json

"AccordationDate": {
            "type": "array",
            "default": [
                {
                    "title": "Find relevant media contacts - multiline title",
                    "description":
                      "Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam quidem ipsam ratione dicta quis cupiditate consequuntur laborum ducimus iusto velit.",
                    "imageUrl": "http://ssse.local/wp-content/uploads/2022/09/P1015596-scaled.jpeg",
                    "baseColor": "249,82,120",
                    "secondColor": "221,9,57"
                  },

ny function

  function updateTitle(event, ind) {
    // var func = JSON.parse(JSON.stringify(attributes.AccordationDate));
    // AccordationDate[ind].title = event.target.value;
return (
prev => (
  setAttributes({AccordationDate: [...prev, {
  ...prev,
 AccordationDate[ind].title: event.target.value }] } )))
}

0
Kasia Strzempek 2 months 2022-09-26T07:36:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse