0

Here is the code

const [somethingChange, setSomethingChange] = useState<Record<string, File>>({
    signature: {} as File,
    document1: {} as File,
  });

const valueChange = (e: File, target: string) => {
    setSomethingChange({ ...somethingChange, target: e });
  };

What I want to do is on valueChange function I am using like this

const file = new File([], 'signature.jpg', { type: 'image/jpeg' });
valueChange(file, 'signature');

But the function always create a new object key value pair.

{
    signature: {},
    document1: {},
    target: File
}

How Can I modify this one

Khant
  • 958
  • 5
  • 20
  • If you want to use the *value* of `target` as the property name, you need to use computed property name syntax: `{ ...somethingChange, [target]: e }`. – T.J. Crowder Sep 06 '22 at 08:08

0 Answers0