Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function App() {
- const [showApplicants, setShowApplicants] = useState(false);
- const [showSpecificApplicant, setShowSpecificApplicant] = useState([]);
- const [applicants, setApplicants] = useState([
- {
- firstName: "Billy",
- background: "Employed",
- id: 1
- },
- {
- firstName: "Sarah",
- background: "Employed",
- id: 2
- },
- {
- firstName: "Vera",
- background: "Student",
- id: 3
- },
- {
- firstName: "Albert",
- background: "Unemployed",
- id: 4
- }
- ]);
- const transitions = useTransition(applicants, item => item.id, {
- from: {
- transform: "translate(-100%, 0)"
- },
- enter: {
- transform: "translate(0%,0)"
- },
- leave: {
- transform: "translate(150%, 0)"
- },
- config: { duration: 3000 }
- });
- const handleApplicants = () => {
- setShowApplicants(!showApplicants);
- setShowSpecificApplicant([]);
- };
- const showDetails = (e, item) => {
- setShowSpecificApplicant(item.id);
- };
- const SpecificApplicant = () => {
- const matchedUser = applicants.find(
- user => user.id === showSpecificApplicant
- );
- return transitions.map(({ item, key, props }) => {
- return showSpecificApplicant === item.id ? (
- <animated.div key={key} style={props}>
- <div
- style={{
- background: "lightblue",
- width: "20%",
- margin: "0 auto",
- textAlign: "center",
- borderRadius: "5px",
- padding: "10px",
- display: "flex",
- flexDirection: "column"
- }}
- >
- <h3 style={{ margin: "0", padding: "0" }}>
- {matchedUser.firstName}
- </h3>
- <p> Current Status: {matchedUser.background}</p>
- </div>
- </animated.div>
- ) : null;
- });
- };
- return (
- <div className="App">
- <h1>Hello</h1>
- <button onClick={handleApplicants}> Show Applicants </button>
- <ul>
- {showApplicants &&
- applicants.map(item => (
- <button onClick={e => showDetails(e, item)}>
- {item.firstName}
- </button>
- ))}
- </ul>
- <SpecificApplicant />
- </div>
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement