#UI input fields useEffect not updating on browser back after form submit

1 messages · Page 1 of 1 (latest)

runic oyster
runic oyster
#

const inputWrap = useRef();

useEffect(() => {
if (inputWrap.current.querySelector("input").defaultValue !== "") {
inputWrap.current.classList.add("is-focused");
}

inputWrap.current.addEventListener("focus", focus, true);
inputWrap.current.addEventListener("blur", blur, true);
inputWrap.current.addEventListener("load", load, true);

function focus() {
  this.classList.add("is-focused");
}

function blur() {
  var input = this.querySelector("input");
  if (input !== null && input.value === "") {
    this.classList.remove("is-focused");
  }
}

function load() {
  var input = this.querySelector("input");
  if (input !== null && input.value !== "") {
    this.classList.add("is-focused");
  }
}

}, []);

#

this is my code so i figured it should run again when i press the back button