B
B
Brake Made2018-03-27 08:17:28
React
Brake Made, 2018-03-27 08:17:28

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 {

If you need additional code, write, I will send :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-03-28
@DanilAndreevich

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 question

Ask a Question

731 491 924 answers to any question