Answer the question
In order to leave comments, you need to log in
How to keep the last value in props?
Good afternoon, I have a page with a search for employees, if the user enters a full name, but there is no such value, then I display an error.
recordit.co/sL1RRx8jCN link to gif.
that's just what the situation is, after the error has appeared, I delete the old value in the input and it is corrected in the error.
How can you save the last value?
Condition code :
render(){
const { error, isLoaded, items , searchValue} = this.props;
if (error) {
return <Center><div><p className={styles.meme}>┬┴┬┴┤( ͡° ͜ʖ├┬┴┬┴ </p>
<p className={styles.textMeme}>Из-за угла появляется ошибка и говорит: {error.message}</p>
</div></Center>;
} else if (!isLoaded) {
return <Center className={styles.LoaderDiv}><Loader type="big" active></Loader></Center>;
} else if (!items.length) {
return <Center><p className={styles.memeSecond}>٩(๏̯๏)۶</p><p className={styles.textMeme}>По запросу {searchValue} ничего не найдено</p></Center>
}else {
Answer the question
In order to leave comments, you need to log in
As I understand it, you have a controlled input . You need to separate the searchValue and input value (let's call it searchInputValue ) in your code. That is, on pressing the Search button, write the value of searchInputValue in state as searchValue , and pass it to the component with an error. As a result , searchInputValue will be used in input , searchValue will be used in error and search query .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question