import React, { useState } from 'react'; import { InputGroup, Container, Form, Button, } from 'react-bootstrap'; import { CSSTransition } from 'react-transition-group'; import putUrlHandler from '../axios/putUrlHandler'; export default () => { const [state, setState] = useState({ url: null, loading: false, result: null, error: false, }); const submit = (evt) => { evt.preventDefault(); if (state.url) { setState({ ...state, loading: true }); putUrlHandler(state.url).then((data) => { setState({ ...state, result: `http://${window.location.host}/u/${data}`.replace('5000', '3000'), loading: false, error: false, }); }).catch((ex) => { if (ex.response && ex.response.data === 'INVALID URL') { setState({ ...state, error: true }); } }); } }; return (

URL Shortener

setState({ ...state, url: evt.target.value })} required /> {state.error && ( Please enter a valid URL )}
{state.result && (
{state.result}
)}
); };