How To Render When The Function Is A Character String
I'm having trouble with React's Render processing. There is a function called func1 and func2, which is called when rendering (eg: return ( )). For example, I want to
Solution 1:
Firstly, React components name must begin with uppercase character, check this question for more details
React - User-Defined JSX Components Not rendering
Secondly instead of storing
{funcName: "Func1"}
you would store
{funcName: Func1}
and then render like
render() {
constFunc1 = obj.funcName;
return<Func1/>
}
or if you can't replace the string with component in your data, you would do
render() {
constFunc1 = eval(obj.funcName);
return<Func1/>
}
Solution 2:
Instead of putting it as element <func2 />
call the function func2()
But you func2 must return a valid react element.
Post a Comment for "How To Render When The Function Is A Character String"