score:0

not 100% this is your problem but i would recommend against trying to bind on the form or whatever. assuming you're storing the input in the state's user object, then you just want to define a submit method, and call it with this.state.user. that method should basically just call your api method.

import react, { component } from 'react'
import { adduser } from '../../actions/adduseraction'
import adduserform from './views/adduserform'
import { connect } from 'react-redux'

class addusercontainer extends component {
  submit(values) {
    console.log(values)
    this.props.adduser(values)
  }

  render() {
    return (
      <div>
        <h1>bjud in användare</h1>
        <adduserform onsubmit={this.submit(this.state.user)} />
      </div>
    )
  }
}

function mapstatetoprops(state) {
  return { user: state.user }
}

export default connect(mapstatetoprops, { adduser })(addusercontainer)

score:1

in your adduserform.js

here you have to add onsubmithandler as a prop for taking in the submit function that's suppose to run on form submit. you then have to pass the onsubmithandler to handlesubmit()

import react from 'react'
import { field, reduxform } from 'redux-form'

const adduserform = ({ handlesubmit, onsubmithandler }) => {
  return (
    <form onsubmit={handlesubmit(onsubmithandler)}>
      <div>
        <field name="email" component="input" type="email" />
      </div>
      <button type="submit">bjud in</button>
    </form>
  )
}
export default reduxform({
  form: 'adduser'
})(adduserform)

in your addusercontainer.js change onsubmit={this.submit.bind(this)} to onsubmithandler={this.submit.bind(this)}


Related Query

More Query from same tag