Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hook does not rerender when text is changed #85

Open
szamanr opened this issue Jul 30, 2024 · 0 comments
Open

hook does not rerender when text is changed #85

szamanr opened this issue Jul 30, 2024 · 0 comments

Comments

@szamanr
Copy link

szamanr commented Jul 30, 2024

problem

when initialising the hook, you pass the text to be spoken as children parameter. my text is coming from a component prop. when the prop is changed after rendering, the play() method still speaks the original text.

there is a set method returned by the hook, which can be used to update e.g. the language, but there is no way to update the text content. having a method like set.children() would work for me.

reproduction

const App = () => {
  const { text, setText } = useState("hi");

  return (
    <div>
      <span>{text}</span>
      <Speak text={text} />
      <button onClick={() => setText("hello")}>change</button>
    </div>
  );
}

const Speak = ({ text }) => {
  const { play } = useTts({
    children: <p>{text}</p>
  });

  return (
    <button onClick={play}>play</button>
  );
}
  1. click "change"
  2. click "play"

expected result: says "hello"
actual result: says "hi"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant