0

I want to send argument for redux action in js , but API developer used numeric name value in API section ( 2fa_code ) now I try to send argument to API i give an error ( An identifier or keyword cannot immediately follow a numeric literal. ) . please help me how can I solve this problem .


export const setTwofaGoogle = ({ 2fa_code }) => (dispatch) => {
  const token = localStorage.getItem("token");
  // Headers
  const config = {
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${token}`,
    },
  };

  // Request body
  const body = {
    2fa_code
  };

  axios
    .post(TWO_FA_CODE_CONFIRM_URL, body, config)
    .then((res) =>
      dispatch({
        type: SET_2FA_METHOD_GOOGLE_SEUCCES,
        payload: res.data,
      })
    )
    .catch((err) => {
      dispatch({
        type: SET_2FA_METHOD_GOOGLE_FAIL,
        payload: err.data,
      });
      console.log(err);
    });
};

error in react

Failed to compile
./src/redux/actions/settingActions.js
  Line 47:14:  Parsing error: Identifier 'setTwofaGoogle' has already been declared

  45 | /* --------------------------  2fa Code Confirm -------------------------- */
  46 | 
> 47 | export const setTwofaGoogle = ({ 2fa_code }) => (dispatch) => {
     |              ^
  48 |   const token = localStorage.getItem("token");
  49 |   // Headers
  50 |   const config = {
This error occurred during the build time and cannot be dismissed.

1 Answer 1

1

Not sure, what this error has to do with the question, because it doesn't say anything about the numeric variable name.

Anyway, for such variables you have no other solution, rather than using bracket notation

export const setTwofaGoogle = data => dispatch => {
  // ...

  const body = {
    '2fa_code': data['2fa_code']
  }
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.