0

I am trying to do this:

return [      
      <div>
        <h2>Quick Links</h2>        
        <ul>
          for(let i=0;i<8;i++) {
            <li>
              <RichText 
                placeholder={__("Link", "yorku")}
                value={links[i]}
                onChange={onChangeLink}
              />
            </li>
          }
        </ul>
      </div>
    ];    
  },

but this is failing. Where can I learn about the syntax allowed here?

Update March 23, 2020:

I wonder if something like this would work:

const listItems = links.map((link) =>  <li>
                  <RichText
                      placeholder={__("Link", "yorku")}
                      value={link}
                      onChange={onChangeLink} />
                  </li>);

return [
    <div>
        <h2>Quick Links</h2>
        <ul>
            {listItems}
        </ul>
    </div>
];
  • Yes you can, but check the React's website for the proper way to work with the loop or list. If you know the proper way of doing it in React, then you'd also be able to do the same in Gutenberg. Good luck. :) – Sally CJ Mar 20 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.