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

243
Vistas
Pass in state variable value, instead of variable in react lambda function

I have this react component:

export const ClientChannelsList = (props) => {
  const [theDate, setTheDate] = useState(null);
  const [theFilter, setTheFilter] = useState({
    collectionQuery: c => c.where('created_stripe', '>=', 1611700523)
  });


  function handleDateChanged(date) {
    setTheDate(date.getTime()/1000);
    setTheFilter({
      collectionQuery: c => c.where('created_stripe', '>=', theDate)
    });

  }
  return (
    <List exporter={exporter} filter={theFilter} {...props} filters={filters} actions={<TheActions/>}>
      <>
        <Datagrid>
          <TextField label="Channel Id" source="ChannelId"/>
          <TextField label="Name" source="Name"/>
          <TextField label="Email" source="EmailAddress"/>
          <TextField label="Subscription Status" source="SubscriptionStatus"/>
          <TextField label="Has Subscription" source="HasSubscription"/>
          <TextField label="Host Channel Id" source="HostChannelId"/>
          <TextField source="HostChannelName"/>
          <DeleteButton label="" redirect={false}/>
        </Datagrid>
        <DatePicker selected={theDate*1000} onChange={(date) => handleDateChanged(date)}/>
      </>
    </List>
  )
};

This component uses the react-admin module

All I am trying to do is to add a custom filter by passing theFilter to the filter prop of the List component. The issue thats happening is that whenever a date is set using DatePicker, the collection query gets passed on as c=>c.where('created_stripe', '>=', theDate), whereas I would want it to take in the value of theDate in this function something like collectionQuery: c=>c.where('created_stripe','>=', 165343454).

So how should I do it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Can you use useEffect for that code to run only once?

export const ClientChannelsList = (props) => {
  const [theDate, setTheDate] = useState(null);
useEffect(() => {
  const [theFilter, setTheFilter] = useState({
    collectionQuery: c => c.where('created_stripe', '>=', 1611700523)
  });
})


  function handleDateChanged(date) {
    setTheDate(date.getTime()/1000);
    setTheFilter({
      collectionQuery: c => c.where('created_stripe', '>=', theDate)
    });

  }
  return (
    <List exporter={exporter} filter={theFilter} {...props} filters={filters} actions={<TheActions/>}>
      <>
        <Datagrid>
          <TextField label="Channel Id" source="ChannelId"/>
          <TextField label="Name" source="Name"/>
          <TextField label="Email" source="EmailAddress"/>
          <TextField label="Subscription Status" source="SubscriptionStatus"/>
          <TextField label="Has Subscription" source="HasSubscription"/>
          <TextField label="Host Channel Id" source="HostChannelId"/>
          <TextField source="HostChannelName"/>
          <DeleteButton label="" redirect={false}/>
        </Datagrid>
        <DatePicker selected={theDate*1000} onChange={(date) => handleDateChanged(date)}/>
      </>
    </List>
  )
};
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