Adding in a scroll button with Ionic React
You can do this with scrollToTop
method of IonContent, but you have to enable scrollEvents
first. In ionic react, the methods can be accessed using refs
. Doesn't look much reacty but at least this works for now.
........
import React, {useRef} from 'react';
const Home: React.FC = (props) => {
const contentRef = useRef<HTMLIonContentElement | null>(null);
const scrollToTop= () => {
contentRef.current && contentRef.current.scrollToTop();
};
return (
.....
<IonContent ref={contentRef} scrollEvents={true}>
................
<IonButton onClick={()=>scrollToTop()}>Scroll to top</IonButton>
</IonContent>
.....
);
};