Hello I want to know how to use State Management(UseState, UseEffects) in Next JS using server-side rendering without using ‘use client’ at the top.
And Will it decrease my page’s performance using State Management(UseState, UseEffects) in client side?
Can I use Framer-Motion in Next JS ?
import Link from 'next/link'
import React from 'react'
import {Box,Button,Input } from '@mui/material';
import SearchIcon from '@mui/icons-material/Search';
import {motion , useScroll, AnimatePresence } from 'framer-motion'
import Image from 'next/image';
function page({ initialData }) {
const [data, setData] = React.useState(initialData);
return (
<h1>Hello {data} </h1>
)
}
export default page;
2
Answers
That is an example of useEffect and useState with NextJS.
No , using
useEffect
anduseState
doesnot lower the performence if used correctly. You can use UseEffect like this to run it on coponent mounting (starting)