Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // client/src/index.js
- import React from 'react';
- import ReactDOM from 'react-dom';
- import { Provider } from 'react-redux';
- import { createStore, applyMiddleware } from 'redux';
- import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
- import App from './components/app';
- import Signin from './components/auth/signin';
- import reducers from './reducers';
- const createStoreWithMiddleware = applyMiddleware()(createStore);
- ReactDOM.render(
- <Provider store={createStoreWithMiddleware(reducers)}>
- <Router>
- <div>
- <Route path="/" component={App} />
- <Route path="/signin" component={Signin} />
- </div>
- </Router>
- </Provider>,
- document.querySelector('.container')
- );
- // client/src/components/auth/signin.js
- import React, { Component } from 'react';
- import { reduxForm } from 'redux-form';
- class Signin extends Component {
- handleFormSubmit({ email, password }) {
- console.log(email, password);
- // Need to do something to log user in
- }
- render() {
- const { handleSubmit, fields: { username, password } } = this.props;
- return (
- <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
- <fieldset className="form-group">
- <label>Username:</label>
- <input {...username} className="form-control" />
- </fieldset>
- <fieldset className="form-group">
- <label>Password:</label>
- <input {...password} className="form-control" />
- </fieldset>
- <button action="submit" className="btn btn-dark">
- Sign in
- </button>
- </form>
- );
- }
- }
- export default reduxForm({
- form: 'signin',
- fields: ['username', 'password']
- })(Signin);
- // client/src/reducers/index.js
- import { combineReducers } from 'redux';
- import { reducer as form } from 'redux-form';
- const rootReducer = combineReducers({
- form
- });
- export default rootReducer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement