export default function loginvia(loginmethod: string) {
const [state, setstate] = useState(loginmethod);
function login() {
body
}
function oauth() {
body
login()
}
function magic_link() {
body
login()
}
return eval(state);
}
import loginvia from "./filename";
const authlogin = loginvia("oauth");
authlogin();
hey folks,i need to use child login function as helper function in different login methods and i cant write login function outside main function body because of hooks and mutations i am using. so, i used eval in return to call string as function. so i can import parent function and use whichever login method for login. so, is this right approach to solve this problem or if not then please suggest me one.
2
Answers
Not sure you need state here, instead of eval I would just use a simple object lookup to the methods.
And since you are using Typescript I would add some typing here to make things a bit nicer.
eg.
The use of eval is generally discouraged in JavaScript due to security risks. You can use this approach by defining separate functions for each login method within the component.