import React from 'react';
import { useEffect } from 'react';
import {useHistory} from './useHistory';


export const RouterCurrent: React.FC = ({children}) => {
  const {updateCurrent} = useHistory();

  const init = () => {
    updateCurrent(location.pathname, location.search);
  }


  window.onload = () => {
    init();
  }



  useEffect(() => {
    window.addEventListener('popstate', () => {
      init();
    });
    return () => {
      window.removeEventListener('popstate', () => {

      });
    }

  }, []);

  return (
    <>
      {children}
    </>
  );
};
