Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live mode in txs page - changes #928

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

giulianoconti
Copy link
Contributor

@giulianoconti giulianoconti commented Jan 23, 2025

@giulianoconti
Copy link
Contributor Author

@valentinoConti
I doubt that using a context for just this is a good idea.
If you think there is a better solution let me know.
Probably using just a useState for the liveMode would be better but it wouldn't meet these requirements.

@valentinoConti
Copy link
Collaborator

@valentinoConti I doubt that using a context for just this is a good idea. If you think there is a better solution let me know. Probably using just a useState for the liveMode would be better but it wouldn't meet these requirements.

Yes it's kinda overkill to have a context only for this, did you try using a ref?

The only thing I don't know its if the ref is going to keep updated when going back from /tx to /txs 🤔

And if it only needs to be applied when user comes back from /tx using the back button, you can detect that with useNavigationType hook from react-router-dom, example:

import React, { useEffect, useRef } from "react";
import { useLocation, useNavigationType } from "react-router-dom";

const RouteComponent = () => {
  const navigationType = useNavigationType();
  const location = useLocation();
  const previousLocationRef = useRef(null);

  useEffect(() => {
    if (navigationType === "POP") {
      console.log("User navigated using the back/forward button");
      console.log("Previous route was:", previousLocationRef.current);
      console.log("Current route is:", location.pathname);
    }

    // Update the previous route
    previousLocationRef.current = location.pathname;
  }, [navigationType, location]);

  return (
    <div>
      <h1>Current Route: {location.pathname}</h1>
    </div>
  );
};

export default RouteComponent;

I still don't like that approach so much but its better than Context

Maybe the best approach can be using a state but not a react useState but a recoil useRecoilState (global state without context), where the default its true, and you add a useEffect where everytime users leaves "/txs" page, its set to true again unless its leaving "/txs" to go to "/tx" 🤔; if this works its probably the best approach for this task

@giulianoconti giulianoconti added the don't merge This pull request shouldn't be merged yet label Jan 23, 2025
@giulianoconti giulianoconti removed the don't merge This pull request shouldn't be merged yet label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants