# React Search UI is remounting its children on state or prop update

**URL:** <https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [November 6, 2020, 8:34am UTC](https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501 "2020-11-06T08:34:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranjeet.tiwari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ranjeet.tiwari/32/55160_2.png) [@ranjeet.tiwari](https://discuss.elastic.co/u/ranjeet.tiwari)\
**Post date:** [November 6, 2020, 8:34am UTC](https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501/1 "2020-11-06T08:34:20Z")

</div>

We are experiencing an issue with the search UI, whenever we perform any action on search ui, it unmount and remount its children. Basically it is remounting its children again n again on any state changes.

**Sample code :**

```auto
 <SearchProvider config={this.config}>
    <WithSearch>
          <TestComponent />
    </WithSearch>
</SearchProvider>

import React from "react";
export class TestComponent extends React.Component{
    componentDidMount(){
        console.log('mounting...')
    }
    render(){
         return <div>Test Component in action.</div>;
    }
}

```

## -----------output in console---------- mounting.... mounting....

any action on search ui component will force remounting TestComponent  
mounting....  
mounting....  
...

@JasonStoltz could you please help us resolving the issue, we want to prevent multiple unmounting and mounting of TestComponent from the dom.

---

<div class="post-metadata">

**Author:** ![ranjeet.tiwari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ranjeet.tiwari/32/55160_2.png) [@ranjeet.tiwari](https://discuss.elastic.co/u/ranjeet.tiwari)\
**Post date:** [November 9, 2020, 7:17am UTC](https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501/2 "2020-11-09T07:17:56Z")

</div>

Could someone please help me?

---

<div class="post-metadata">

**Author:** ![constancecchen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/constancecchen/32/71762_2.png) [@constancecchen](https://discuss.elastic.co/u/constancecchen)\
**Post date:** [November 30, 2020, 7:48pm UTC](https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501/3 "2020-11-30T19:48:50Z")

</div>

Hey Ranjeet - sorry for the very late response on this. I've pinged @JasonStoltz for back-up, but my initial gut instinct is that we're unlikely to make a change/bugfix in the near future to this behavior, although you can certainly [open an issue](https://github.com/elastic/search-ui/issues) in the repo for it.

In the meanwhile, if it's feasible for your codebase, could I suggest moving away from React class components/`componentDidMount` and instead using [React functional components](https://reactjs.org/docs/components-and-props.html) combined with [`useEffect`](https://reactjs.org/docs/hooks-effect.html)? `useEffect` allows you to filter reactions to changes by specific prop or variables, which might be able to help you with working around `componentDidMount`.

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [December 1, 2020, 2:06pm UTC](https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501/4 "2020-12-01T14:06:38Z")

</div>

@ranjeet.tiwari Try looking at the [https://github.com/elastic/search-ui/blob/master/ADVANCED.md#mapcontexttoprops](https://github.com/elastic/search-ui/blob/master/ADVANCED.md#mapcontexttoprops) option. This _should_ let you specify which items from state you're using, and will ONLY re-render when those state items are updated.

As a side note, I'm still unsure why it's causing a full re-mount as it is currently. 🤔

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 29, 2020, 2:06pm UTC](https://discuss.elastic.co/t/react-search-ui-is-remounting-its-children-on-state-or-prop-update/254501/5 "2020-12-29T14:06:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
