Can I access a function in a stateless component? I know that the function can be accessable if change to class component. However, as I know. Hooks is incomptable with class component. Please feel fee to comment. Thank you.
# This example is incorrect, for describe the idea only.
const StatelessComponent = () => {
const StatelessComponentFunction = () => {
return 1;
}
}
const thisFun = new TestComponent();
let A = thisFun.StatelessComponentFunction();
Update on 16, October 2019, solution found.
Base on the information on these pages "https://hackernoon.com/javascript-state-encapsulation-without-classes-in-2019-97e06c6a9643" and "https://basarat.gitbooks.io/typescript/docs/javascript/closure.html". I found a solution.
Modified
const StatelessComponent = () => {
return {
StatelessComponentFunction() {
return 1;
}
}
}
const thisFun = StatelessComponent();
console.log(thisFun.StatelessComponentFunction());