Skip to content

Commit f67ecef

Browse files
Merge pull request #527 from GetStream/vishal/theme-context-optimization
Optimizing ThemeContext
2 parents fc97316 + 61cd081 commit f67ecef

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Version 3.x is a major revamp of the SDK and comes with **many breaking changes*
3636
- Removed css string notation for styles on theme
3737
- Added displayName to components with bracket notation denoting the theme path e.g. `MessageStatus.displayName = 'MessageStatus{message{status}}';` indicates the theme path would be modified via `const customTheme: DeepPartial<Theme> = { message: { status: { ...customizations } } }`.
3838

39-
Please find detailed docs about this release in our [wiki](https://github.com/GetStream/stream-chat-react-native/wiki#v30-beta)
39+
Please find detailed docs about this release in our [wiki](https://github.com/GetStream/stream-chat-react-native/wiki#v300)
4040

4141
## [2.2.2] 2021-02-07
4242

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Currently we are working on publishing v3.0.0. Its in beta phase (`v3.0.0-beta.2
3030
- [Chat UI Kit](https://getstream.io/chat/ui-kit/)
3131
- [Release Notes](https://github.com/GetStream/stream-chat-react-native/releases)
3232
- [Internationalization (i18n)](https://github.com/GetStream/stream-chat-react-native/wiki/Internationalization-(i18n))
33-
- [Cookbook](https://github.com/GetStream/stream-chat-react-native/wiki#v30-beta) 🚀
33+
- [Cookbook](https://github.com/GetStream/stream-chat-react-native/wiki#v300) 🚀
3434

3535
## Contents
3636

@@ -50,12 +50,12 @@ Currently we are working on publishing v3.0.0. Its in beta phase (`v3.0.0-beta.2
5050

5151
To use this library you need to ensure you match up with the correct version of React Native you are using.
5252

53-
| `stream-chat-react-native` version | Required React Native Version |
54-
| ----------------------------------------- | --------- |
55-
| `3.x.x` (beta) | `>= 0.60` |
56-
| `2.x.x` | `>= 0.60` |
57-
| `1.x.x` | `>= 0.59` |
58-
| `0.x.x` | `*` |
53+
| `stream-chat-react-native` version | React Native Version | `stream-chat` Version |
54+
| ---------------------------------- | --------------------- | --------------------- |
55+
| `3.x.x` (beta) | `>= 0.60` | `>= 3.0.0` |
56+
| `2.x.x` | `>= 0.60` | `< 3.0.0` |
57+
| `1.x.x` | `>= 0.59` | `< 3.0.0` |
58+
| `0.x.x` | `*` | `< 3.0.0` |
5959

6060
## 📖 React Native Chat Tutorial
6161

@@ -94,7 +94,7 @@ Check out our tutorial on how to build a slack clone using react-native and stre
9494

9595
## 📋 Docs
9696

97-
Please check following url for all the detailed documentation - https://github.com/GetStream/stream-chat-react-native/wiki#v30-beta
97+
Please check following url for all the detailed documentation - https://github.com/GetStream/stream-chat-react-native/wiki#v300
9898

9999
## 💬 Keep in mind
100100

src/contexts/themeContext/ThemeContext.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import React, { useContext } from 'react';
2-
3-
import cloneDeep from 'lodash/cloneDeep';
1+
import React, { useContext, useMemo } from 'react';
42
import merge from 'lodash/merge';
53

64
import { defaultTheme, Theme } from './utils/theme';
@@ -18,13 +16,18 @@ export const ThemeContext = React.createContext({} as Theme);
1816
export const ThemeProvider: React.FC<ThemeProviderInputValue> = (props) => {
1917
const { children, style } = props;
2018
const { theme } = useTheme();
21-
const modifiedTheme =
22-
Object.keys(theme).length === 0
23-
? cloneDeep(defaultTheme)
24-
: cloneDeep(theme);
25-
if (style) {
26-
merge(modifiedTheme, style);
27-
}
19+
const modifiedTheme = useMemo(() => {
20+
const finalTheme =
21+
Object.keys(theme).length === 0
22+
? JSON.parse(JSON.stringify(defaultTheme))
23+
: JSON.parse(JSON.stringify(theme));
24+
25+
if (style) {
26+
merge(finalTheme, style);
27+
}
28+
29+
return finalTheme;
30+
}, [theme, style]);
2831

2932
return (
3033
<ThemeContext.Provider value={modifiedTheme}>

0 commit comments

Comments
 (0)