I've tried to pass click handler to SignIn component, but it doesn't work for me. I get log and then page refreshes
Auth
class:
class Auth extends Component {
login() {
console.log('Clicked'); //only this method works
fetch('/api/auth/signin', {
method: 'POST',
body: JSON.stringify(this.state),
headers: {
'Content-Type': 'application/json; charset=utf8'
}
}).then((response) => {
if (response.status === 200) {
this.props.history.push('/api/categories')
}
})
}
render() {
return (
<SignIn onCustomClick={this.login}/> //onClick handler
)
}
SignIn component
export default function SignIn(props) {
const {onCustomClick} = props; // props
return (
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
onClick={onCustomClick} // onClick handler
>)
}