Created
October 3, 2017 17:26
-
-
Save eduard-tkv/94592d77a047c1242c7be9a9fd39e439 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//using ES6 | |
import React from 'react'; | |
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.handleClick = this.handleClick.bind(this) | |
} | |
handleClick(e) { | |
e.preventDefault() | |
this.props.history.push('/redirected'); | |
} | |
render() { | |
return ( | |
<div> | |
<button onClick={this.handleClick}> | |
Redirect!!! | |
</button> | |
</div> | |
) | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i am not using a class i am using function how can i use history.push this is my code :
import React from 'react';
import Avatar from '@material-ui/core/Avatar';
import Button from '@material-ui/core/Button';
import CssBaseline from '@material-ui/core/CssBaseline';
import TextField from '@material-ui/core/TextField';
import Link from '@material-ui/core/Link';
import Grid from '@material-ui/core/Grid';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import Container from '@material-ui/core/Container';
import axios from 'axios';
import { Redirect } from 'react-router'
/*
import {PostData} from '../../node_modules/'; */
const useStyles = makeStyles(theme => ({
'@global': {
body: {
backgroundColor: theme.palette.common.white,
},
},
paper: {
marginTop: theme.spacing(8),
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
avatar: {
margin: theme.spacing(1),
backgroundColor: theme.palette.secondary.main,
},
form: {
width: '100%',
marginTop: theme.spacing(3),
},
submit: {
margin: theme.spacing(3, 0, 2),
},
}));
export default function SignUp() {
const classes = useStyles();
const [values, setValues] = React.useState({
realm: '',
username: '',
email: '',
address: '',
password: '',
});
const handleChange = name => event => {
setValues({ ...values, [name]: event.target.value });
};
const newUser = {
realm: values.realm,
username: values.username,
address: values.address,
email: values.email,
password: values.password
}
const handleSubmit = e => {
};
function addUser(newUser){
axios.post('http://localhost:3000/api/Users', newUser).then(res => ).catch(err => console.log(err));
}
return (
);
}