Created
September 12, 2018 16:08
-
-
Save icyJoseph/0b07cc5ac167e980645d77ef86517294 to your computer and use it in GitHub Desktop.
Putting the portable BasicModal in a React 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 BasicModal from "../components/BasicModal"; | |
import FixButton from "../components/FixButton"; | |
import { MyModalContent, ReactHeader } from "../components/Commons"; | |
import { bodyClickFix } from "../utils"; | |
import "./App.css"; | |
export default class App extends Component { | |
state = { open: false, counter: 0, fixed: false }; | |
componentDidMount() { | |
document.body.addEventListener("click", this.countUp); | |
} | |
countUp = () => | |
this.setState(prevState => ({ counter: prevState.counter + 1 })); | |
fix = () => bodyClickFix(this.setFix); | |
setFix = () => this.setState({ fixed: true }); | |
render() { | |
const { counter, fixed } = this.state; | |
return ( | |
<div className="App"> | |
<ReactHeader counter={counter} /> | |
<BasicModal> | |
<MyModalContent /> | |
</BasicModal> | |
<FixButton fixed={fixed} callback={this.fix} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment