0

I have a bunch of conditionals here. Is there any way to simplify this? Also, if you could, could you explain what the '?' in 'migrated.value?.user' means? Thanks

 {migrated.value === null ||
  migrated.value?.user === null ? null : migrated.user
      ?.migrated_to_new_login === null ||
    migrated.user?.migrated_to_new_login === 0 ? null : (
    <MigratedToNew
      passwordValue={passwordValue}
      setPasswordValue={setPasswordValue}
    />
  )}
Junaid Razaq
  • 241
  • 5
  • 14
  • 1
    The ?. is called optional chaining. It's a newish javascript feature that prevents a crash if the object property does not exist at runtime. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining – Dov Rine Oct 11 '21 at 02:24
  • 1
    simplified: if(! migrated?.value?.user?.migrated_to_new_login) return null; return () – Dov Rine Oct 11 '21 at 02:30

0 Answers0