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

forceUpdate not work in child component GuardGraph #31019

Open
wowok-ai opened this issue Sep 22, 2024 · 1 comment
Open

forceUpdate not work in child component GuardGraph #31019

wowok-ai opened this issue Sep 22, 2024 · 1 comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@wowok-ai
Copy link

wowok-ai commented Sep 22, 2024

export default function GuardSetting (props:any) {
  const [, forceUpdate] = useReducer(x => x + 1, 0);

    return (
      <Paper sx={{ width: '100%', pt:'1em', }} >
        <SettingHeader name={'Launch Guard'}/>
        <ReactFlowProvider>
          <GuardGraph {...props} forceUpdate={forceUpdate}/>
        </ReactFlowProvider>
      </Paper>
    );
}

Is there any more elegant way to refresh GuardGraph without using window.location.reload()?
Thx.

@wowok-ai wowok-ai added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 22, 2024
@RioChndr
Copy link

Hi, let me help to answer this question. Force update can be done by changing the key of component/element.

const [key, setKey] = useState('first-key');
const forceUpdate = () => { setKey(crypto.randomUUID()); }
return (
<GuardGraph key={key} {...props}
)

by doing this, the component will be forced to re-render. Read more this documention about key. Hopefully this answer your question!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants