Learn the fundamentals of React, including simple and class components, state, props, and submitting form data.
Last active
December 28, 2018 16:39
-
-
Save h4091/9091fbf0c3f071df91810a11ee3f612b to your computer and use it in GitHub Desktop.
Test30
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
<div id="root"></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
class Chosen extends React.Component { | |
componentDidMount() { | |
this.$el = $(this.el); | |
this.$el.chosen(); | |
} | |
componentWillUnmount() { | |
this.$el.chosen("destroy"); | |
} | |
render() { | |
return ( | |
<div> | |
<select className="Chosen-select" ref={el => this.el = el}> | |
{this.props.children} | |
</select> | |
</div> | |
); | |
} | |
} | |
function Example() { | |
return ( | |
<Chosen> | |
<option>vanilla</option> | |
<option>chocolate</option> | |
<option>strawberry</option> | |
</Chosen> | |
); | |
} | |
ReactDOM.render( | |
<Example />, | |
document.getElementById("root") | |
); |
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
<script src="https://unpkg.com/react/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.6.2/chosen.jquery.min.js"></script> |
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
.Chosen-select { | |
width: 150px; | |
} |
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
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.6.2/chosen.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment