This is my senario:
1. Request application CMS (content management system) for the content of the page.
2. Return CMS "<div>Hi,<SpecialButton color="red">My Button</SpecialButton></div>"
3. The application consumes the content, displays the corresponding component with the data provided in the attribute.
I can't figure out how to do step 3 in React mode, any advice is welcome.
Thanks @Glenn Reyes, here is Sandbox to show the problem.
import React from 'react'; import { render } from 'react-dom'; const SpecialButton = ({ children, color }) => ( <button style={{color}}>{children}</button> ); const htmlFromCMS = ` <div>Hi, <SpecialButton color="red">My Button</SpecialButton> </div>`; const App = () => ( <div dangerouslySetInnerHTML={{__html: htmlFromCMS}}> </div> );
Here is a live demo made by Ways. The string "<div v-demo-widget></div>" can be viewed as a Vuejs directive and rendered. Source code .
javascript html compilation reactjs content-management-system
Andy chen
source share