Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.props.postUsers(this.state.username,this.state.password,this.state.errors)
- export function postUsers(username, password, errors) {
- let users = {
- username,
- password,
- };
- let self = this;
- return{
- type: "USERS_POST",
- payload: axios({
- method:'POST',
- url: url,
- data: users,
- contentType: 'application/json',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- }
- })
- .then(success => {
- console.log('sucesssssssss', success)
- })
- .catch(({response}) => {
- self.setState({errors: response.data});
- })
- }
- }
- import React, {Component} from 'react';
- import { connect } from 'react-redux';
- import {bindActionCreators} from 'redux';
- import { postUsers } from '../actions/usersAction';
- class Layout extends Component {
- constructor(props){
- super(props);
- this.state = {
- username: '',
- password: '',
- errors: [],
- }
- }
- onUserUpdate(filed, event){
- if (filed === 'username') {
- this.setState({
- username: event.target.value
- });
- }
- if (filed ==='password') {
- this.setState({
- password: event.target.value
- });
- }
- }
- handlePostUsers(e){
- e.preventDefault();
- this.props.postUsers(this.state.username,this.state.password,this.state.errors)
- }
- render() {
- console.log('this.state.errors',this.state.errors);
- return (
- <div className="App">
- <input name="username" onChange={this.onUserUpdate.bind(this, 'username')}/>
- <input name="username" onChange={this.onUserUpdate.bind(this, 'password')}/>
- <button onClick={(e) => this.handlePostUsers(e)}>Go ahead</button>
- </div>
- );
- }
- }
- function mapStateToProps(state) {
- return {
- act: state.users,
- };
- }
- function matchDispatchToProps(dispatch) {
- return bindActionCreators({postUsers}, dispatch)
- }
- export default connect(mapStateToProps, matchDispatchToProps)(Layout);
Add Comment
Please, Sign In to add comment