Home > Enterprise >  Jodit-react undefined property "name"
Jodit-react undefined property "name"

Time:06-26

I think Jodit is not handling react event at all?

part of the code:

let [something,setSomething] = useState({'s':''})
let {s} = something
let handleChange = (e)=>{
        setSomething(
            {
                ...something,
                [e.target.name]:e.target.value  //error occuring here.

            }
        )

    }

and then when trying to rendering jsx:

<JoditEditor required className = 's' name='s' value={s} onChange={(e)=>handleChange(e)}></JoditEditor

and in dev browser I get :

enter image description here

as title mentioned, and of course this does not happen with normal html element.

CodePudding user response:

Props of onChange event is string content, not event. I updated your code.

let [something,setSomething] = useState({s:''})
let {s} = something
let handleChange = (key, newContent)=>{
    setSomething(
       {
          ...something,
          [key]: newContent
       }
    )
}

<JoditEditor
  required
  className = 's'
  name='s'
  value={s}
  onChange={(newContent) => handleChange('s', newContent)}>
</JoditEditor>
  • Related