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

Removed React context mention in the documentation #2841

Merged
merged 4 commits into from
Jan 31, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions docs/Translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,7 @@ const App = () => (

## Translating Your Own Components

The translation system use the React `context` to pass translations down the component tree. To translate a sentence, use the `translate` function from the context. Of course, this assumes that you've previously added the corresponding translation to the `messages` props of the `Admin` component.

```jsx
// in src/MyHelloButton.js
import React, { Component } from 'react';
import PropTypes from 'prop-types';

class MyHelloButton {
render() {
const { translate } = this.context;
return <button>{translate('myroot.hello.world')}</button>;
}
}
MyHelloButton.contextTypes = {
translate: PropTypes.func,
};

// in src/App.js
const messages = {
en: {
myroot: {
hello: {
world: 'Hello, World!',
},
},
},
};
```

However, using the context makes components harder to test. That's why react-admin provides a `translate` Higher-Order Component, which simply passes the `translate` function from context to props:
The react-admin package provides a `translate` Higher-Order Component, which simply passes the `translate` function to props of wrapped component:
Copy link
Collaborator

@djhi djhi Jan 31, 2019

Choose a reason for hiding this comment

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

Suggested change
The react-admin package provides a `translate` Higher-Order Component, which simply passes the `translate` function to props of wrapped component:
React-admin provides a `translate` Higher-Order Component, which simply injects the `translate` function to the wrapped component:


```jsx
// in src/MyHelloButton.js
Expand Down