I want to declare multiple baseUrl here to a single variable for my User Search Bar -
const baseUrl = http://host:8082/user/phone
and http://host:8082/user/email
Please Help !!!
I want to declare multiple baseUrl here to a single variable for my User Search Bar -
const baseUrl = http://host:8082/user/phone
and http://host:8082/user/email
Please Help !!!
Need more context as to why you want to do this: one variable represents one value, so in what situation would you want it to represent two things? How would you or the computer know what it was?
const baseUrls = [
"http://host:8082/user/phone",
"http://host:8082/user/email",
];
const baseUrls = {
phone: "http://host:8082/user/phone",
email: "http://host:8082/user/email",
};
const baseUrl = "http://host:8082/user";
// Somewhere else in the code:
const userPhone = `${baseUrl}/phone`;
const userEmail = `${baseUrl}/email`;
Please tell me how I do this?
import axios from "axios"
import { put, takeLatest } from "redux-saga/effects"
import { actions, t } from "./actions"
const baseUrl = "http://host:8082/user/phone"
function* loadUserData(action) {
const response = yield axios.get(`${baseUrl}/${action.name}`)
yield put(actions.loadUserDataSuccess(response.data))
}
export function* watchLoadUserData() {
yield takeLatest(t.LOAD_USER_DATA, loadUserData)
}
Here inline 8 in the response variable, I want to pass for both email and phone URL so that I can search for the result through one search box at once.
You just make two requests: these are two separate endpoints, two separate locations. One request to the phone endpoint, one to the email endpoint.
const phoneResponse = yield axios.get(`${phoneUrl}/${action.name}`);
const emailResponse = yield axios.get(`${emailUrl}/${action.name}`)
const responseData = /* join the data in the above two responses together */;
yield put(actions.loadUserDataSuccess(responseData))
No programming language will allow you to have an arbitrary number of values assigned to one variable - you need to put them in a collection (the examples I showed, one was in an array, one in an object, and one attached the different paths to the common base url).