diff --git a/src/App.js b/src/App.js index 9571e2e..f2394dd 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,7 @@ import React from 'react'; import { Switch, Route } from 'react-router-dom'; -import Greeting from './Greeting'; + +import { Greeting } from './Greeting/Greeting'; import Board from './Board'; import { Lottery } from './Lottery/Lottery'; import configService from './services/configService'; diff --git a/src/Greeting/index.js b/src/Greeting/Greeting.tsx similarity index 65% rename from src/Greeting/index.js rename to src/Greeting/Greeting.tsx index 1c4997b..c6e015c 100644 --- a/src/Greeting/index.js +++ b/src/Greeting/Greeting.tsx @@ -1,19 +1,20 @@ -import React, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import './greeting.scss'; import { GreetingForm } from './GreetingForm'; import Dialog from '../Board/Dialog'; import { getUpperUrl } from '../utils/urlHelpers'; +import { RouteComponentProps } from 'react-router-dom'; -const Greeting = (props) => { +export const Greeting: React.FC = (props) => { const [modalDisplay, setModalDisplay] = useState(false); const [user, setUser] = useState({ name: '', greetings: '', imgUrl: '' }); - const onSubmit = (formData) => { + const onSubmit = useCallback((formData: WeddiApp.Post.UserInput) => { setUser(formData); setModalDisplay(true); - setTimeout(() => { props.history.push(getUpperUrl()); }, 5000); - }; + setTimeout(() => { props.history.push(getUpperUrl(props.match.url)); }, 5000); + }, [setUser, setModalDisplay, props.history, props.match.url]); return (
@@ -26,5 +27,3 @@ const Greeting = (props) => {
); }; - -export default Greeting;