i'm using React-cookies, redux, redux-thunk and hooks.
I don't understand how to store the value of " token " as a cookie.
this is the Component App.js
<Provider store={store}>
<CookiesProvider>
<BrowserRouter>
<Switch>
<Route exact path="/release/:id" component={Release} render={() => (<Login cookies={this.props.cookies} />)} />
<Route exact path="/login" render={() => (<Login cookies={this.props.cookies} />)} component={Login} />
</Switch>
</BrowserRouter>
</CookiesProvider>
</Provider>
actually the Login
component is made as hook
I receive the value of the token because of call made with this component
function Form({ handleSubmit, login }, props) {
const [token, setToken] = useState(undefined);
const onSubmit = (user) => {
login(user);
};
return (
<form onSubmit={handleSubmit(onSubmit)} className={styles.flexColumn}>
<div className={styles.username}>
<P>username</P>
<Field name="username" component="input" type="text" className={styles.input} />
</div>
<div className={styles.password}>
<P>password</P>
<Field
name="password"
component="input"
type="text"
className={styles.input}
/>
</div>
<div className={styles.downSection}>
<Flex>
<div>
<P>
Serve Aiuto?
</P>
</div>
<a href="#">
<div className={styles.contactLink}>
<P>Contattaci</P>
</div>
</a>
</Flex>
<Button type="submit" text="Accedi" />
</div>
</form>
);
}
Form.propTypes = {
handleSubmit: PropTypes.func.isRequired,
login: PropTypes.func.isRequired,
};
const mapStateToProps = (state, ownProps) => ({
cookies: ownProps.cookies,
}, console.log(ownProps));
const mapDispatchToProps = {
login: loginAction,
};
const enhance = compose(
connect(mapStateToProps, mapDispatchToProps),
reduxForm({ form: 'login' }),
);
export default enhance(Form);
How could i store the value token
as a cookie ? i got this value thanks to loginAction
I must use the library react-cookies.
Thanks.