diff --git a/src/App.tsx b/src/App.tsx index a53698a..cd95dbc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,26 +1,28 @@ -import React from 'react'; -import logo from './logo.svg'; +import React, { useState } from 'react'; +import {usePrevious} from './hooks/UsePrevios' import './App.css'; +import styles from './hooks/UsePrevios.module.css' -function App() { - return ( -
-
- logo -

- Edit src/App.tsx and save to reload. -

- - Learn React - -
-
- ); +const Counter = () => { + const [value, setValue] = useState(0); + const previousValue = usePrevious(value); + + return ( +
+
+

Current value: {value}

+

Previous value: {previousValue}

+
+ +
+ ); } -export default App; +export default Counter; diff --git a/src/hooks/UsePrevios.module.css b/src/hooks/UsePrevios.module.css new file mode 100644 index 0000000..5195f2b --- /dev/null +++ b/src/hooks/UsePrevios.module.css @@ -0,0 +1,43 @@ +.increment{ + width: 140px; + height: 60px; + border-radius: 10px; + border: none; + background-color: darksalmon; + font-size: 20px; + font-weight: 600; + color: #25140f; + transition: 0.5s; + +} +.increment:hover{ + background-color: #985e4b; + color: #b6b1b1; +} +.current_value{ + +} +.previous_value{ + +} +.box{ + width: 45vw; + height: 45vh; + display: flex; + justify-content: space-evenly; + align-items: center; + flex-direction: column; + background-color: bisque; + margin-top: 180px; + margin-left: 390px; + border-radius: 17px; +} +.flex{ + width: 48vw; + display: flex; + justify-content: space-evenly; + align-items: center; + margin-top: 15px; + font-size: 21px; + color: #3a2119; +} \ No newline at end of file diff --git a/src/hooks/UsePrevios.tsx b/src/hooks/UsePrevios.tsx new file mode 100644 index 0000000..6876942 --- /dev/null +++ b/src/hooks/UsePrevios.tsx @@ -0,0 +1,12 @@ +import { useEffect, useRef } from 'react'; + +export const usePrevious = (value: number) => { + const ref = useRef(); + + useEffect(() => { + ref.current = value; + }, [value]); + + return ref.current; +}; +