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

[RFR] Add useTranslate hook #3188

Merged
merged 12 commits into from
May 6, 2019
Merged

[RFR] Add useTranslate hook #3188

merged 12 commits into from
May 6, 2019

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented May 4, 2019

  • Add useTranslate Hook
  • Document it
  • Test it
  • Use it in simple example
  • Use it in demo example
  • upgrade ra-core to use it instead of withTranslate in function components
  • upgrade ra-ui-material-ui to use it instead of withTranslate in function components
  • use useTranslate in class components (requires translating these components to functions, to be done sometime in the future)
// in src/MyHelloButton.js
import React from 'react';
-import { translate } from 'react-admin';
+import { useTranslate } from 'react-admin';

-const MyHelloButton = ({ translate }) => {
+const MyHelloButton = () => {
+   const translate = useTranslate();
    return (
        <button>{translate('myroot.hello.world')}</button>
    );
}

-export default translate(MyHelloButton);
+export default MyHelloButton;

@fzaninotto fzaninotto added this to the 3.0.0 milestone May 4, 2019
@fzaninotto fzaninotto changed the title [WIP] Add useTranslate hook [RFR] Add useTranslate hook May 4, 2019
@fzaninotto
Copy link
Member Author

Switching to RFR

@@ -16,30 +15,29 @@ const styles = {
},
};

const LinkToRelatedProducts = ({ classes, record, translate }) => (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff looks much better with 'hide whitespace changes' turned on.

docs/Translation.md Outdated Show resolved Hide resolved
@djhi djhi merged commit cb0bf12 into next May 6, 2019
@djhi djhi deleted the useTranslate branch May 6, 2019 10:25
@fzaninotto fzaninotto mentioned this pull request May 7, 2019
40 tasks
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

Successfully merging this pull request may close these issues.

2 participants