Next.js Discord

Discord Forum

useState is not changing

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
The Value in the Input Box changes but when using "setTheInputBoxValue" it wont do anything

15 Replies

Giant pandaOP
    const [theInputBoxValue, setTheInputBoxValue] = useState('');

                                <input
                                    className="bg-[#202020] rounded-lg w-full px-3 py-3 text-sm leading-tight text-gray-200 outline-2 outline-[#3B4BA7] outline-none transition-all duration-500"
                                    type="text"
                                    required
                                    rules={{
                                        required: true,
                                    }}
                                    minLength={1}
                                    maxLength={14}
                                    placeholder="App Name"
                                    onChange={(e) => { console.log(e.target.value); setTheInputBoxValue(e.target.value)}}
                                />
the console.log prints out in the dev console
but when testing with a button
                                        onClick={() => { console.log(theInputBoxValue) }}

it wont do anything than a empty print
Nextjs Version: 14.0.2
Chinese Egret
I think the state is changing but you have to set ‘value’ props on the ‘input’ tag
American black bear
<input
className="bg-[#202020] rounded-lg w-full px-3 py-3 text-sm leading-tight text-gray-200 outline-2 outline-[#3B4BA7] outline-none transition-all duration-500"
type="text"
required
rules={{
required: true,
}}
value={theInputBoxValue}
minLength={1}
maxLength={14}
placeholder="App Name"
onChange={(e) => { console.log(e.target.value); setTheInputBoxValue(e.target.value)}}
/>
American black bear
send your code screenshot
@American black bear send your code screenshot
Giant pandaOP
it worked fine on nextjs 13
American black bear
yes, it working
it work in any version
Giant pandaOP
Yea but it dosnt work for me sadly
its just freezed
its in a Modal btw