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

Rerender problem #68

Closed
retyui opened this issue Jul 12, 2019 · 1 comment
Closed

Rerender problem #68

retyui opened this issue Jul 12, 2019 · 1 comment

Comments

@retyui
Copy link
Contributor

retyui commented Jul 12, 2019

How to solve the next problem:

// @flow
import React, { useState, useCallback } from 'react';
import fbt, { IntlViewerContext } from 'fbt';

const Links = () => {
  return <fbt desc="test">Text link</fbt>;
};

const App = () => {
  const setState = useState({})[1];
  const onClick = useCallback(() => {
    IntlViewerContext.locale = Math.random() > 0.5 ? 'en_GB' : 'de_DE';
    setState({});
  }, [setState]);

  return (
    <div onClick={onClick}>
      <fbt desc="test">Title</fbt>
      <Links />
      {/*
         rerender a `<Links/>` component never would call
         and text does not change when set new locale
      */}
    </div>
  );
};
@retyui retyui closed this as completed Jul 12, 2019
@jrwats
Copy link
Contributor

jrwats commented Jul 12, 2019

Hi @retyui, I see you closed this, but I was going to say the state needs to depend on the locale. You can see how the Example app does this here:

https://github.com/facebookincubator/fbt/blob/master/demo-app/src/example/Example.react.js#L89-L90

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

No branches or pull requests

2 participants