Passing RichText attributes to function onChange

I have four RichText elements in a custom Gutenberg block I am developing, and they are all very similar except for the “name” attribute, which is currently hard-coded. What I need to do is pass in the value of the change, and the value of the name attribute to a function before using SetAttribute. Is this possible?

// the function that I need to use to SetAttribute after seeing the name   
const onChangeTitle = ( value, name ) => {
    console.log(name);
};

// the RichText element
<RichText
    tagName="h3"
    className="h5 text-light"
    placeholder="Link Title"
    name="linkOne"
    value={ linkOneTitle }
    onChange={ ( value ) => onChangeTitle( { value, name } ) }
/>

I can post the full code, but there are several different fields and elements that I didn’t want to have clutter the post. The RichText works just fine and if I use SetAttribute in the onChangeTitle it works without issue to save the title, but I need to set the title in a specific way based on the name.

0

Leave a Comment