Last active
November 21, 2019 11:03
-
-
Save takaki/51769f214c980f6f362463c7b7f38cd1 to your computer and use it in GitHub Desktop.
Reactでinputを扱う ref: https://qiita.com/takaki@github/items/8125535791b1bab8c85a
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
var React = require('react'); | |
var ReactDOM = require('react-dom'); | |
var App = React.createClass({ | |
render: function() { | |
return ( | |
<div> | |
<label>value a</label> | |
<input type="radio" name="aradio" value="A" checked="checked" /> <br /> | |
<label>value b</label> | |
<input type="radio" name="aradio" value="B" /> | |
<hr /> | |
<label>text input</label> | |
<input type="text" name="atext" value="" /> | |
</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
var App = React.createClass({ | |
getInitialState: function() { | |
return { | |
radio: "a", | |
text: "" | |
} | |
}, | |
render: function() { | |
return ( | |
<div> | |
<label>value a</label> | |
<input type="radio" name="aradio" value="A" checked={this.state.radio === 'a'} | |
onChange={() => this.setState({radio: 'a'})}/> <br /> | |
<label>value b</label> | |
<input type="radio" name="aradio" value="B" checked={this.state.radio === 'b'} | |
onChange={() => this.setState({radio: 'b'})}/> | |
<hr /> | |
<label>text input</label> | |
<input type="text" name="atext" value={this.state.text} | |
onChange={(e) => this.setState({text: e.target.value})}/> | |
</div> | |
) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment