Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 17, 2022 05:41 pm GMT

?Error in Substring function in react

I am getting data from an API specifically a string. But that string too large. I want to reduce it to only 15 letter.
So

function Banner() {    const [movie,setMovie] = useState([])    useEffect( () =>{        async function fetchData(){            const req = await axios.get("some API request")//req is a string for sure            setMovie(req)        }         fetchData();    },[])const desciption = movie.substring(0,15)return(<h1>    {desciption}    </h1>)

It render for the first time but on reload it throughs error every time I reload that substring is not defined


Original Link: https://dev.to/hamsof/substring-function-in-react-5daa

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To