Created
May 23, 2017 02:06
-
-
Save HappyZombies/166fb21e979975067738b794030ac8a4 to your computer and use it in GitHub Desktop.
React Materialize, Input component prop 'defaultValue' does not update on component re-render.
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 React, { Component } from 'react' | |
import logo from './logo.svg' | |
import './App.css' | |
import MyForm from './MyForm' | |
class App extends Component { | |
constructor () { | |
super() | |
this.state = {name: 'Paul'} | |
} | |
componentDidMount () { | |
// After 2 seconds, update name state to John | |
setTimeout(function () { | |
this.setState({name: 'John'}) | |
}.bind(this), 2000) | |
} | |
render () { | |
return ( | |
<MyForm name={this.state.name} /> | |
) | |
} | |
} | |
export default App |
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 React, { Component } from 'react' | |
import {Input} from 'react-materialize' | |
class MyForm extends Component { | |
componentWillUpdate (nextProp, nextState) { | |
console.log('Yes component should update') | |
} | |
render () { | |
alert(`Rendering MyForm, value of this.props.name is: ${this.props.name}`) | |
return ( | |
<div> | |
<h1>{this.props.name}</h1> | |
<Input defaultValue={this.props.name} /> | |
</div> | |
) | |
} | |
} | |
export default MyForm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment