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

log element not calling setContent on changes #124

Open
samingle opened this issue Aug 5, 2022 · 0 comments
Open

log element not calling setContent on changes #124

samingle opened this issue Aug 5, 2022 · 0 comments

Comments

@samingle
Copy link

samingle commented Aug 5, 2022

Looking at the blessed source, it appears that react-blessed isn't triggering the set content event when updating a log element reactively.

Failing example:
In this version, the log won't keep scroll pinned to the bottom, because the set content event is never fired.

export const Debugger: React.FC<Debugger> = ({ debugEntries, isFocused }) => {
  return (
    <log
      label="Debugger"
      top="75%"
      width="100%"
      height="25%"
      scrollOnInput={true}
      focusable={true}
      keys={true}
      class={styles}>
        {debugEntries.join("\n")}
    </log>
  );
};

Working example:
In this version, the log will keep scroll pinned to the bottom, because we are explicitly calling setContent when the underlying content changes.

export const Debugger: React.FC<DebuggerProps> = ({ debugEntries, isFocused }) => {
  const ref = useRef<blessed.Widgets.Log>(null)
  useEffect(() => {
    if (ref.current) {
      ref.current.setContent(debugEntries.join("\n"))
    }
  }, [debugEntries])
      
  return (
    <log
      label="Debugger"
      ref={ref}
      top="75%"
      width="100%"
      height="25%"
      scrollOnInput={true}
      focusable={true}
      keys={true}
      class={styles} />
  );
};
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