Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README (example with React Hooks) #783

Merged
merged 3 commits into from
Nov 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 17 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,37 @@ const customStyles = {
// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/)
Modal.setAppElement('#yourAppElement')

class App extends React.Component {
constructor() {
super();

this.state = {
modalIsOpen: false
};

this.openModal = this.openModal.bind(this);
this.afterOpenModal = this.afterOpenModal.bind(this);
this.closeModal = this.closeModal.bind(this);
function App(){
openModal = openModal.bind(this);
afterOpenModal = afterOpenModal.bind(this);
closeModal = closeModal.bind(this);
diasbruno marked this conversation as resolved.
Show resolved Hide resolved
const [modalIsOpen,setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}

openModal() {
this.setState({modalIsOpen: true});
}

afterOpenModal() {
function afterOpenModal() {
// references are now sync'd and can be accessed.
this.subtitle.style.color = '#f00';
subtitle.style.color = '#f00';
}

closeModal() {
this.setState({modalIsOpen: false});
function closeModal(){
setIsOpen(false);
}

render() {
return (
<div>
<button onClick={this.openModal}>Open Modal</button>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={this.state.modalIsOpen}
onAfterOpen={this.afterOpenModal}
onRequestClose={this.closeModal}
isOpen={modalIsOpen}
onAfterOpen={afterOpenModal}
onRequestClose={closeModal}
style={customStyles}
contentLabel="Example Modal"
>

<h2 ref={subtitle => this.subtitle = subtitle}>Hello</h2>
<button onClick={this.closeModal}>close</button>
<h2 ref={_subtitle => subtitle = _subtitle}>Hello</h2>
diasbruno marked this conversation as resolved.
Show resolved Hide resolved
<button onClick={closeModal}>close</button>
<div>I am a modal</div>
<form>
<input />
Expand All @@ -104,7 +95,6 @@ class App extends React.Component {
</Modal>
</div>
);
}
}

ReactDOM.render(<App />, appElement);
Expand Down