Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. // client/src/index.js
  2.  
  3. import React from 'react';
  4. import ReactDOM from 'react-dom';
  5. import { Provider } from 'react-redux';
  6. import { createStore, applyMiddleware } from 'redux';
  7. import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
  8.  
  9. import App from './components/app';
  10. import Signin from './components/auth/signin';
  11. import reducers from './reducers';
  12.  
  13. const createStoreWithMiddleware = applyMiddleware()(createStore);
  14.  
  15. ReactDOM.render(
  16. <Provider store={createStoreWithMiddleware(reducers)}>
  17. <Router>
  18. <div>
  19. <Route path="/" component={App} />
  20. <Route path="/signin" component={Signin} />
  21. </div>
  22. </Router>
  23. </Provider>,
  24. document.querySelector('.container')
  25. );
  26.  
  27. // client/src/components/auth/signin.js
  28. import React, { Component } from 'react';
  29. import { reduxForm } from 'redux-form';
  30.  
  31. class Signin extends Component {
  32. handleFormSubmit({ email, password }) {
  33. console.log(email, password);
  34. // Need to do something to log user in
  35. }
  36.  
  37. render() {
  38. const { handleSubmit, fields: { username, password } } = this.props;
  39. return (
  40. <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
  41. <fieldset className="form-group">
  42. <label>Username:</label>
  43. <input {...username} className="form-control" />
  44. </fieldset>
  45. <fieldset className="form-group">
  46. <label>Password:</label>
  47. <input {...password} className="form-control" />
  48. </fieldset>
  49. <button action="submit" className="btn btn-dark">
  50. Sign in
  51. </button>
  52. </form>
  53. );
  54. }
  55. }
  56.  
  57. export default reduxForm({
  58. form: 'signin',
  59. fields: ['username', 'password']
  60. })(Signin);
  61.  
  62. // client/src/reducers/index.js
  63.  
  64. import { combineReducers } from 'redux';
  65. import { reducer as form } from 'redux-form';
  66.  
  67. const rootReducer = combineReducers({
  68. form
  69. });
  70.  
  71. export default rootReducer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement