I have Function With Parameters in Context File and the Parameters need to pass it onClick, But it's show error "onLogin is not a function"
Context.js
export const AuthContext = createContext(undefined);
export default Context({children}) {
const CheckUser = (Username, Password) => {
const Data = {
email: Username,
password: Password
}
API.post('/login', Data)
.then( response => {
console.log(response.data);
})
.catch( error => {
console.log(error.message);
})
}
<AuthContext.Provider value={{onLogin: CheckUser}}>
{children}
</AuthContext.Provider>
}
Child.js
const onLogin = useContext(Context);
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
<form>
<TextField onChange={e => setUsername(e.target.value)} />
<TextField onChange={e => setPassword(e.target.value)} />
<Button onClick={() => onLogin(username, password)}>Login</Button>
</form>