Skip to content

Commit 0ffce95

Browse files
committed
add more examples for hooks
1 parent b54d50f commit 0ffce95

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

example/src/App.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
2-
import * as MessageSource from 'react-message-source';
2+
import { Provider as MessageSourceProvider } from 'react-message-source';
33

4+
import Hooks from './Hooks';
45
import {
56
LocalizedLabel,
67
LocalizedLabelCurried,
@@ -18,15 +19,13 @@ export default function App() {
1819
<React.Fragment>
1920
<p>The content below is localized, see Greeting.js for more information.</p>
2021

21-
<MessageSource.Provider value={translations}>
22+
<MessageSourceProvider value={translations}>
2223
<LocalizedLabel />
23-
2424
<LocalizedLabelCurried />
25-
2625
<PrefixedLocalizedLabel />
27-
2826
<LocalizedLabelWithNamedParams />
29-
</MessageSource.Provider>
27+
<Hooks />
28+
</MessageSourceProvider>
3029
</React.Fragment>
3130
);
3231
}

example/src/Hooks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import { useMessageSource } from 'react-message-source';
3+
4+
export default function Hooks() {
5+
const { getMessage } = useMessageSource();
6+
return <span>Translation with a hook: {getMessage('hello.world')}</span>;
7+
}

0 commit comments

Comments
 (0)