Into React application I use this code to set value as url path param:
const [exchangeId, setExchangeId] = useState('');
.....
const endURL = `?page=${paginationState.activePage}&sort=${paginationState.sort},${paginationState.order}&exchangeId=${exchangeId}`;
.....
When I don't set with some value exchangeId I get always empty url param exchangeId=
Do you know how I can implement a check if exchangeId is not set to not include exchangeId= into http link?
You can use conditional (ternary) operators.
const exchangeId = '';
const paginationState = {
activePage: 1,
sort: 1,
order: 1
}
const endURL = `?page=${paginationState.activePage}&sort=${paginationState.sort}&order=${paginationState.order}${exchangeId ? `&exchangeId=${exchangeId}` : ''}`;
console.log(endURL);