This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createForm } from 'final-form' | |
import createDecorator from 'final-form-calculate' | |
// Create Form | |
const form = createForm({ onSubmit }) | |
// Create Decorator | |
const decorator = createDecorator( | |
// Calculations: | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createForm } from 'final-form' | |
import arrayMutators from 'final-form-arrays' | |
// Create Form | |
const form = createForm({ | |
mutators: { | |
// potentially other mutators here | |
...arrayMutators | |
}, | |
onSubmit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Clears a form value */ | |
const clear = ([name], state, { changeValue }) => { | |
changeValue(state, name, () => undefined) | |
} | |
/** Converts a form value to uppercase **/ | |
const upper = ([name], state, { changeValue }) => { | |
changeValue(state, name, value => value && value.toUpperCase()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MyCustomButton from './ui/MyCustomButton' | |
class MyClicker extends Component { | |
constructor() { | |
super() | |
this.state = { clicked: false } | |
} | |
handleClick = () => { | |
// "this" is the right instance of this component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MyCustomButton from './ui/MyCustomButton' | |
class MyClicker extends Component { | |
constructor() { | |
super() | |
this.state = { clicked: false } | |
this.handleClick = this.handleClick.bind(this) // Problem solved! | |
} | |
handleClick() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MyCustomButton from './ui/MyCustomButton' | |
class MyClicker extends Component { | |
constructor() { | |
super() | |
this.state = { clicked: false } | |
} | |
handleClick() { | |
this.setState({ clicked: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MyCustomButton from './ui/MyCustomButton' | |
class MyClicker extends Component { | |
constructor() { | |
super() | |
this.state = { clicked: false } | |
} | |
render() { | |
return <div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
The following can replace the file in the Field Arrays example | |
(https://github.com/erikras/redux-form/tree/master/examples/fieldArrays) to demonstrate this functionality. | |
**/ | |
import React from 'react' | |
import { connect } from 'react-redux' | |
import { Field, FieldArray, reduxForm, formValueSelector } from 'redux-form' | |
import validate from './validate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentWillReceiveProps(nextProps) { | |
if(!this.props.deadDrop && nextProps.deadDrop) { | |
// dispatch an action to clear the value | |
this.props.clearDeadDrop() | |
// do what your case officer has instructed, Agent | |
this.performOperation(nextProps.deadDrop) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Answer to https://stackoverflow.com/questions/40349005/how-to-initialize-a-fieldarray-from-state-using-redux-form | |
* | |
* How to run: | |
* | |
* 1) Clone redux-form repo | |
* 2) Run the Initialize From State example (https://github.com/erikras/redux-form/tree/master/examples/initializeFromState) | |
* 3) Replace InitializeFromStateForm.js with this file | |
* 4) ... | |
* 5) Profit! |