Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught (in promise) TypeError: setExercises is not a function

I am making an Recat gym website using an API, in this when I search for something it gets the data and shows the error ie., the data is not passing to setExercise for displaying it to screen. this is the function given for searching onClick={handlesearch}:

const SearchExercises = (setExercises) => {

const handleSearch= async()=>{
            if(search){
                const exerciseData = await fetchData('https://exercisedb.p.rapidapi.com/exercises', exerciseOptions);
                const SearchExercises = exerciseData.filter((exercise)=>
                    exercise.name.toLowerCase().includes(search));
                setSearch('');
                setExercises(SearchExercises);
            }
        }
}

The useState is defined in the home.js file

function Home() {
  const [bodyPart,setBodyPart] = useState('all')
  const [exercises, setExercises] = useState([])
  return (
    <Box><SearchExercises setExercises={setExercises} bodyPart={bodyPart} setBodyPart={setBodyPart}/>
    </Box>
  )
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you’re passing props to a React component, the first argument contains all of your props. The common pattern is to destructure them like so

const SearchExercises = ({ setExercises, bodyPart, setBodyPart }) => {
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading