DEV Community

My
My

Posted on

1 1

ErrorBoundary does not re-render app when place below react-router

I am adding ErrorBoundary to my app but I found that when I add ErrorBoundary below react-router, the app doesn't re-render on route change until I manually force refresh.

Here's the sample code. I'm using BrowserRouter here. I would like to understand why the order of placement is important here.

App doesn't re-render until force refresh

<Router>
    <div className="app-shell">
        <ErrorBoundary>
            <Navbar />
            <div className="app-main">
                <Sidebar project={this.props.currentProject} />
                <MainContentRouter />
            </div>
            <ToastContainer />
        </ErrorBoundary>
    </div>
<Router>

WORKS FINE

<ErrorBoundary>
    <Router>
        <div className="app-shell">
            <Navbar />
            <div className="app-main">
                <Sidebar project={this.props.currentProject} />
                <MainContentRouter />
            </div>
            <ToastContainer />
        </div>
    <Router>
</ErrorBoundary>

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more