question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change value prop not works

See original GitHub issue
const [text, setText] = useState('')

const onTextChange = (textTyped) => {
    textTyped = (textTyped.split(' ').length > 3) ? `${textTyped.split(' ').splice(0, 3).join(' ')}</p>` : textTyped
    console.log('textTyped', textTyped)
    setText(textTyped)
}

<ReactQuill
    theme="snow"
    value={text}
    onChange={onTextChange}
    modules={reactQuillModules}
    formats={reactQuillFormats}
    className="mb-4"
/>

How you can see here (https://i.imgur.com/wFkYMDB.png), above React Quill state text is working fine (it was cut to 3 words), but value prop it’s not updated.

_Originally posted by @gleidsonh in https://github.com/zenoamaro/react-quill/issues/588#issuecomment-643687425_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
zenoamarocommented, Jun 17, 2020

Hello there @gleidsonh!

I have played with the reproduction – the issue here is that calling setText with the same value it has at that moment does not trigger a prop update. This is the behavior of the setState hook.

Until Quill offers a way to prevent edits (as explained in the README), unfortunately there’s not much that can be fixed on ReactQuill’s side.

However, you can easily modify your example, like this, which will work because a new object doesn’t === the previous one, even if the contents are the same:

export default function App() {
  const [text, setText] = useState({value: ''}) // Store object instead of string

  const onTextChange = (textTyped) => {
    textTyped = (textTyped.split(' ').length > 3) ? `${textTyped.split(' ').splice(0, 3).join(' ')}</p>` : textTyped
    console.log('textTyped', textTyped)
    setText({value: textTyped})
  }

  return <ReactQuill
    theme="snow"
    value={text.value}
    onChange={onTextChange}
  />
}
0reactions
channyeintuncommented, Dec 8, 2022

The same issue still exists. Why was it closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component not updating when I change the props that I pass ...
A component only updates once either its state changes or its props change. A state is a variable or set of variables which...
Read more >
Why React Child Components Don't Update on Prop Changes
In React, it's a common problem to have child components that don't re-render when you expect them to. In particular, a common problems...
Read more >
Lifting State Up - React
Let's see how this works step by step. First, we will replace this.state.temperature with this.props.temperature in the TemperatureInput component. For now ...
Read more >
How to update a component's prop in ReactJS — oh yes, it's ...
This setup works in most of the scenarios. But what if you need to update the prop of the child component, and the...
Read more >
Component prop not changing when select value changes ...
Coding example for the question Component prop not changing when select value changes-Reactjs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found