[SOLVED] Uncaught ReferenceError: get is not defined rkt query redux toolkit


This Content is from Stack Overflow. Question asked by Youssef Idraiss

I’m trying to run simple api slice using rkt query of redux toolkit, but i always get this error : Uncaught ReferenceError: get is not defined, not sure if it’s a bug, or something i do wrong

    import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'

export const jokesApi = createApi({
    reducerPath: 'jokesApi',
    baseQuery: fetchBaseQuery({
      baseUrl: 'https://official-joke-api.appspot.com/jokes/',
    endpoints: (builder) => ({
      getJokeByType: builder.query({
        query: (type) => `${type}/random`,
  export const { useGetJokeByTypeQuery } = jokesApi;

my app.js

import {useGetJokeByTypeQuery } from './ApiSlice'

const App = () => {

  const {
} = useGetJokeByTypeQuery('programming')

  return (
      <button onClick={get}>click here</button>

export default App

error :

Uncaught ReferenceError: get is not defined
    at App (App.js:15:1)
    at renderWithHooks (react-dom.development.js:16305:1)
    at mountIndeterminateComponent (react-dom.development.js:20074:1)
    at beginWork (react-dom.development.js:21587:1)
    at beginWork$1 (react-dom.development.js:27426:1)
    at performUnitOfWork (react-dom.development.js:26557:1)
    at workLoopSync (react-dom.development.js:26466:1)
    at renderRootSync (react-dom.development.js:26434:1)
    at recoverFromConcurrentError (react-dom.development.js:25850:1)
    at performConcurrentWorkOnRoot (react-dom.development.js:25750:1)


This line in your app is using a variable named get, but you have nowhere written any code that actually defines that variable:

      <button onClick={get}>click here</button>

This Question was asked in StackOverflow by Youssef Idraiss and Answered by phry It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?