update filter value on props change

This commit is contained in:
Konstantin Schaper
2020-09-10 10:48:37 +02:00
parent 4ee7ba4641
commit 498f0ca219

View File

@@ -21,10 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React, { ChangeEvent, FormEvent } from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import React, {ChangeEvent, FormEvent} from "react";
import {WithTranslation, withTranslation} from "react-i18next";
import styled from "styled-components";
import { createAttributesForTesting } from "../devBuild";
import {createAttributesForTesting} from "../devBuild";
type Props = WithTranslation & {
filter: (p: string) => void;
@@ -59,6 +59,16 @@ class FilterInput extends React.Component<Props, State> {
event.preventDefault();
};
componentDidUpdate = (prevProps: Props) => {
const { value } = this.props;
const { value: stateValue } = this.state;
if (prevProps.value !== value && value !== stateValue) {
this.setState({
value: value || ""
});
}
};
render() {
const { t, testId } = this.props;
return (