Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
JS: Problem with with displaying a select list in modal on page

I have a problem with displaying a list for user selection. When I open the page for the first time, it works correctly. But after I reload the page, the users "disappear" or are unloaded. Before reload After reload. Here is the code I have.

My-page:

const Page = observer(() => {
  const { project } = useContext(Context);
  const [modalVisible, setModalVisible] = useState(false);

  useEffect(() => {
    fetchUsers().then((data) => project.setUsers(data));
  }, []);

  return (
      <Container>
        <Button onClick={() => setModalVisible(true)}>
          ChooseUser
        </Button>
        <ChooseUser show={modalVisible} onHide={() => setModalVisible(false)} />
      </Container>
  );
});
export default Page;

Modal:

const ChooseUser = observer(({ show, onHide }) => {
  const { project } = useContext(Context);
 
  return (
    <Modal show={show} onHide={onHide}>
      <Form>
            <Form.Select>

              {/* The problem with this list */}

              {project.users.map((user) =><option>{user.username}</option>)}
            </Form.Select>
        </Form>
    </Modal>
  );
});

Context creating in index.js:

export const Context = createContext(null);

ReactDOM.render(
  <Context.Provider value={{
    project: new ProjectStore(),
  }}
  >
    <App />
  </Context.Provider>,
  document.getElementById('root'),
);

ProjectStore

export default class ProjectStore {
  constructor() {
    this._users = [];
    makeAutoObservable(this);
  }

  setUsers(value) {
    this._users = value;
  }

  get users() {
    return this._users;
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You might try Array.from(project.users).map((user) ... instead of project.users.map((user) ... and see if that helps.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda