Here is my code ... I want to set default value of a input field by react-hook-form but its showing me the variable(problemName) value "undefine" ... I am checking its value in console.log(problemName) ...its showing my expected value
import axios from 'axios';
import React, { useState, useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { useNavigate, useParams } from 'react-router-dom';
const SingleProble = () => {
const navigate = useNavigate();
const { problemNames } = useParams();
const [data, setData] = useState([]);
useEffect(() => {
axios.get(`http://localhost:5000/problems/math/${problemNames}`)
.then(res => {
setData(res.data)
})
}, [problemNames])
const { problemName, score, problemDetails, level, problemAns, tried, solved, failed } = data
const defaultValues = {name:problemName}
const { register, handleSubmit } = useForm({ defaultValues })