`What does this line of code mean?
M
M
mr jeery2018-02-10 17:57:19
JavaScript
mr jeery, 2018-02-10 17:57:19

What does this line of code mean?

Confused by __regex and axios.get(`${API_URL}?sort=-createdAt${search}`)
Are regular expressions that weird?
https://learn.javascript.ru/regular-expressions-ja... reading about reg. expressions did not help to understand what was happening. I understand that they are passing a variable to the server in order to write it to the database

export const search = () => {
  return (dispatch, getState) => {
    const description2 = getState().todo.description2;
    const search = (description2) ? `&description2__regex=/${description2}/` : '';
    axios.get(`${API_URL}?sort=-createdAt${search}`)
      .then((res) => dispatch({type: 'TODO_SEARCHED', payload: res.data}));
  };
};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-02-10
@jeerjmin

Optionally, a regular expression is added to the query string of the request, available via the description2__regex key .
If the question is only about syntax, then template strings are used .

A
Alexey, 2018-02-10
@Qwal

These are template substitutions from Es6
https://developer.mozilla.org/en/docs/Web/JavaScri...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question