Replacing a button with custom attributes #267
helloingob
started this conversation in
General
Replies: 1 comment
-
Can you use destructuring assignment? For example: {Parser(props.content, {
replace: domNode => {
if (domNode.name === 'button' && domNode.attribs && domNode.attribs.method !== '' && domNode.attribs.param !== '') {
// see object destructuring below
const { method, param, ...restProps } = domNode.attribs;
return <button {...restProps} onClick={() => sendCommand(method, param)}>XYZ</button>;
}
}
})} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
I got a html string from an API and I want to replace some attributes. The attribute "method" and "param" should be removed and used for "onClick" and the rest of the attributes should be kept.
Example input string
React
This code is working great, but how do I keep other attributes like "class" or "id"? And how do I access the button's name "ABC" and print it instead of "YXZ". I know "innerText", but it's not valid.
How can I solve this?
Any help greatly appreciated :)
Thanks
Beta Was this translation helpful? Give feedback.
All reactions