-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
Using TriStateCheckbox component with null value gives console error.
Warning:
valueprop oninputshould not be null. Consider using an empty string to clear the component orundefinedfor uncontrolled components.
I am using the TriStateCheckbox as it is described in the component description https://primereact.org/tristatecheckbox/#basic. However, this provides errors in the console in the browser dev tools. I cannot not prevent the error from the log. Even if I initialized the state to false or true, it gives more errors when changing the state to null.
Warning: A component is changing a controlled input to be uncontrolled. This is likely caused by the value changing from a defined to undefined, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.
I'm using the code example:
import React, { useState } from "react";
import { TriStateCheckbox } from 'primereact/tristatecheckbox';
export default function BasicDemo() {
const [value, setValue] = useState(null);
return (
<div className="card flex flex-column align-items-center gap-3">
<TriStateCheckbox value={value} onChange={(e) => setValue(e.value)} />
<label>{String(value)}</label>
</div>
);
}Any comment would be really appreciated! Thank you!
Reproducer
No response
System Information
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
primereact: latest => 10.8.3
react: 18.3.1 => 18.3.1Steps to reproduce the behavior
-
Go to the demo page https://primereact.org/tristatecheckbox/#basic (primereact version 10.8.3)
-
Click "Edit in StackBlitz" on the Basic TriStateCheckbox example.

-
Go to the StackBlitz page for "PrimeReact Demo" and wait the packages are installed for the component.
-
Open the browser dev tools.
-
Click the checkbox to change the state from
nulltotrue.
Expected behavior
The errors should not appear in the console of dev tools.

