I'm creating 2 endponits using React RTK query
export const countryApi = createApi({
reducerPath: "countryApi",
baseQuery: fetchBaseQuery({ baseUrl: "https://restcountries.com/v3.1/" }),
endpoints: (builder) => ({
getCountries: builder.query({
query: () => `all/`
}),
getCountryByName: builder.query({
query: (name) => `name/${name}`
})
})
});
Then i need to show results with condition, if the state of search input change i call the second endponit otherwise i use the 1st enpoint to show all the list of countries
// country search state
const [search, setSearch] = useState("");
let countryData;
countryData =
search === ""
? useGetCountriesQuery().data
: useGetCountryByNameQuery(search,{skip: search ===""}).data;
But i got an error enter image description here