10 examples of 'usehistory react' in JavaScript

Every line of 'usehistory react' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
31export function useHistory<TParams extends Record<string, unknown>>({
32 pushOn,
33}: {
34 pushOn: TParams
35}): void {
36 const isMounted = useRef(false)
37
38 useEffect(() => {
39 if (!isMounted.current) {
40 isMounted.current = true
41 return
42 }
43
44 pushState(removeEmpty(pushOn))
45 }, [JSON.stringify(pushOn)])
46}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

5export function useHistory() {
6 let pathname = getPathname();
7 let [state, setState] = useState({ pathname });
8
9 useEffect(() => {
10 function handler() {
11 let pathname = getPathname();
12 setState(state =>
13 state.pathname != pathname ? { pathname } : state
14 );
15 }
16 return subscribe(handler);
17 }, []);
18 return [pathname, redirect];
19}
23export function History(props: HistoryProps) {
24 React.useEffect(() => {
25 if (process.env.NODE_ENV !== 'production') {
26 console.warn(
27 `Deprecation Warning: "<History>" is deprecated. It will be removed in a future version.`,
28 )
29 }
30 }, [])
31
32 return (
33 <NaviContext.Consumer>
34 {context => props.children(context.navigation._history)}
35 </NaviContext.Consumer>
36 )
37}
5export function useHistory() {
6 if (process.env.NODE_ENV !== 'production') {
7 console.warn(
8 `Deprecation Warning: "useHistory()" is deprecated. It will be removed in a future version.`,
9 )
10 }
11
12 return React.useContext(NaviContext).navigation._history
13}
25export function useHistory() {
26 return useContext(HistoryContext);
27}
12function useHistory() {
13 return useContext( Context );
14}
11function useHistoryReplay( {
12 restore,
13} ) {
14 const { state: { replayState } } = useHistory();
15 useEffect( () => {
16 if ( ! replayState ) {
17 return;
18 }
19 const { current, pages, selection, story, capabilities } = replayState;
20 restore( {
21 pages,
22 current,
23 story,
24 selection,
25 capabilities,
26 } );
27 }, [ restore, replayState ] );
28}
9export function useHistory() {
10 if (__DEV__) {
11 invariant(
12 typeof useContext === "function",
13 "You must use React >= 16.8 in order to use useHistory()"
14 );
15 }
16
17 return useContext(Context).history;
18}
12function useHistoryEntry( {
13 story,
14 current,
15 pages,
16 selection,
17 capabilities,
18} ) {
19 const { actions: { appendToHistory } } = useHistory();
20 useEffect( () => {
21 appendToHistory( {
22 story,
23 current,
24 pages,
25 selection,
26 capabilities,
27 } );
28 }, [ appendToHistory, story, current, pages, selection, capabilities ] );
29}
16export default function HistoryHandler( { children } ) {
17 const ref = useRef();
18 const { undo, redo } = useDispatch( 'core/editor' );
19
20 useEffect( () => {
21 const onBeforeInput = ( event ) => {
22 if ( event.inputType === 'historyUndo' ) {
23 event.preventDefault();
24 undo();
25 } else if ( event.inputType === 'historyRedo' ) {
26 event.preventDefault();
27 redo();
28 }
29 };
30
31 ref.current.addEventListener( 'beforeinput', onBeforeInput );
32
33 return () => {
34 ref.current.removeEventListener( 'beforeinput', onBeforeInput );
35 };
36 } );
37
38 return (
39 <div ref={ ref }>
40 { children }
41 </div>
42 );
43}

Related snippets