【发布时间】:2020-02-25 13:19:11
【问题描述】:
我想从普通的 JavaScript 函数中调用一个 ReactJS 函数(函数式组件)。它不打印输出,因为 ReactJS 使用 JSX 语法。是否可以从普通的 JS 功能调用 ReactJS 功能组件?我的示例代码在这里:
class Extra extends React.Component {
//This is the ReactJS class component
}
function Greeting() {
// This is the ReactJS functional component
// I wanted to call this ReactJS functional component from the
normal JavaScript function
return (<Extra/>);
}
function Calling() {
// This is normal JavaScript function which I have defined in the
separate file. From this function I wanted to call the ReactJS
function.
Greeting();
}
我试过这个。我从普通的 JS 函数中调用了 ReactJS 函数组件。它在 ReactJS 函数内部,但它没有在浏览器上显示 JSX 代码(ReactJS 类组件的 JSX 语法)
提前致谢
【问题讨论】:
-
请提及代码理解问题
-
请edit your question 而不是在 cmets 中发布代码。很难阅读。也请使用它周围的`标签将其格式化为代码。
-
我现在已经发布了代码。所以,请通过它。
标签: javascript reactjs