Created
January 12, 2020 09:48
-
-
Save emmabostian/7af066576ae9a2d1c852e19eba044121 to your computer and use it in GitHub Desktop.
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, { useState } from "react"; | |
import { useTransition } from "react-spring"; | |
import ReactDOM from "react-dom"; | |
import Modal from "./Modal"; | |
import "./styles.css"; | |
function App() { | |
const [modalVisible, setModalVisible] = useState(false); | |
const fadingAnimation = useTransition(modalVisible, null, { | |
from: { opacity: 0, transform: "translateY(-40px)" }, | |
enter: { opacity: 1, transform: "translateY(0px)" }, | |
leave: { opacity: 0, transform: "translateY(-40px)" } | |
}); | |
return ( | |
<div className="App"> | |
<button | |
className="show-modal-button" | |
onClick={() => setModalVisible(true)} | |
> | |
Show modal | |
</button> | |
{fadingAnimation.map( | |
({ item, key, props: style }) => | |
item && ( | |
<Modal | |
style={style} | |
closeModal={() => setModalVisible(false)} | |
key={key} | |
/> | |
) | |
)} | |
</div> | |
); | |
} | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<App />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment