Skip to content

Instantly share code, notes, and snippets.

@emmabostian
Created January 12, 2020 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmabostian/7af066576ae9a2d1c852e19eba044121 to your computer and use it in GitHub Desktop.
Save emmabostian/7af066576ae9a2d1c852e19eba044121 to your computer and use it in GitHub Desktop.
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