[英]How do I call ReactJS class component and functional component from normal Javascript function?
我想從普通的 JavaScript ZC1C4145268E178A8 中調用 ReactJS function(功能組件)。 它不打印 output 因為 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 function中調用了ReactJS功能組件。 It is going inside the ReactJS function but its not displaying the JSX code on the browser ( JSX sytax of the ReactJS Class component)
提前致謝
Yes you can call Component class function from normal javascript function, but you need to make that react function static then call from noraml javascript by className.react_function()
class Extra extends React.Component {
//This is the ReactJS class component
static Greeting=()=>{
console.log("Greeting from react class function");
}
}
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.
Extra.Greeting();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.