From 1ac51111f704d71de50c75eaee6990aeabb3d98b Mon Sep 17 00:00:00 2001 From: alxshelepenok Date: Sat, 9 Feb 2019 15:54:31 +0300 Subject: [PATCH] Autoscrolling on mobile devices --- src/components/Page/Page.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/Page/Page.js b/src/components/Page/Page.js index 4c6dd6f..d7ce8c0 100644 --- a/src/components/Page/Page.js +++ b/src/components/Page/Page.js @@ -1,15 +1,23 @@ -import React from 'react'; +import React, { useRef, useEffect } from 'react'; import styles from './Page.module.scss'; -const Page = ({ title, children }) => ( -
-
- { title &&

{title}

} -
- {children} +const Page = ({ title, children }) => { + const pageRef = useRef(); + + useEffect(() => { + pageRef.current.scrollIntoView(); + }); + + return ( +
+
+ { title &&

{title}

} +
+ {children} +
-
-); + ); +}; -export default Page; +export default Page; \ No newline at end of file