Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
React How to back to previous page with filters still in place

Having a hard time trying to figure this out.

I Have 2 Components

  1. A filter component & A table view component
  2. A enhanced view of number table view with more info and functionality

From component 2 i want to go back to component 1 but have the filters still in place?

How can i acheive this?

I've tried

this.props.history.push('/1');

It goes back but doesn't keep the filters?

export default class FilterComponent extends React.Component {
    constructor(props) {
        super(props)
        this.state = {name:[]}
    }
    

    componentDidMount() {
        fetch("https://jsonplaceholder.typicode.com/todos")
            .then((response) => response.json())
            .then(
                (data) => data.map(e => 
                      this.setState({name:[...this.state.name,  e.id]})
                  ))
    }




    onTrigger = (event) => {
        this.props.parentCallback(event.target.value);
        event.preventDefault();
        
    }

   

    render() {

        if(this.state.name.length < 1) {

            return (
                <div>
                <p1> Loadings</p1>
                </div>
            )
        } else {
            return (
                <div className="contactfForm">
    <select onChange={this.onTrigger}>
        <option> ID </option>
        {this.state.name.map((result)=>(<option title={result}>{result}</option>))}
    </select>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I guess you are rendering the filters twice, inside component1 and again inside component2. If you want to navigate and preserve the state, you have two react-based options, and a JS one:

MOVING FILTERS OUTSIDE ROUTER SWITCHER

If you render the filters outside the Switcher of the router, when changing route only the component1 and component2 will rerender, but not the filters.

STORING FILTERS STATE IN A GLOBAL STATE

If rendering the filters outside the Switcher of your Router is not feasible (Because maybe the filters are not rendered in every page of your app) you could save the filter state in a global state (Using for example, React Contexts, see https://reactjs.org/docs/context.html; or Redux).

If you use React Contexts, you could create the provider ouside the router, and inside the Filters component retrieve and modify its values. This way you will mantain the state between components.

SAVING FILTER STATE IN LOCAL STORAGE

If you want to preserve the state also when refreshing the page, you could store the filter state in the Local Storage of the Browser. Every time the Filters component is rendered, you would retrieve the value from the Local Storage, and every time the filters are modified, you would save it. That will also make that when changing the page, as the Local Storage is mantained, the filter state is mantained too.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!