Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

134
Vistas
How to properly send date param to axios in React

I wanted to send date as param to service with axios but when I send it goes as

messageStartDate=2021-12-21T11%3A47%3A54.810Z&messageEndDate=2021-12-21T11%3A47%3A59.718Z

I wanted to send as Iso format but there is %-A and some other things. How can I fix it.

this is how I store the date in redux.

const params = new URLSearchParams();
if (MessageDateStartValueRedux !== null)
        params.append('messageStartDate',new Date(MessageDateStartValueRedux).toISOString());
    if (MessageDateEndValueRedux !==null)
        params.append('messageEndDate',new Date(MessageDateEndValueRedux).toISOString());
    if (ValueDateStartValueRedux !== null)
        params.append('valueStartDate',new Date(ValueDateStartValueRedux).toISOString());
    if (MessageDateEndValueRedux !== null)
        params.append('valueEndDate',new Date(MessageDateEndValueRedux).toISOString());

    dispatch(setUrlParamsReducer(params));

and this is how I use it

const getQueryString = () => `${DEFAULT_URL}?page=${currentPage}&size=${pageSize}`+status;

const param = useSelector(state => state.urlParamsReducer);

console.log(param.toString());
const loadData = () => {
    const queryString = getQueryString();
    if ((queryString !== lastQuery || param.toString() !== lastParam.toString()) && !loading) { 
        axios.get(queryString, {params: param})
            .then((response) => {
                setRows(response.data.data);
                setTotalCount(response.data.totalCount);
            }).catch(() => setLoading(false));
    }
}
useEffect(() => loadData(), [param,getQueryString()]);
7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

%3a is the url encoding of a ':' char. The decoded url is

messageStartDate=2021-12-21T11:47:54.810Z&messageEndDate=2021-12-21T11:47:59.718Z

as expected

7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.