Skip to content

Commit 8d6d290

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
Use mobx-react-lite & new useSignals hook (codesandbox#1961)
1 parent 2ad667d commit 8d6d290

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

packages/app/src/app/pages/CLI/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import { inject, observer } from 'mobx-react';
1+
import { observer } from 'mobx-react-lite';
22
import React, { useEffect } from 'react';
33

44
import Navigation from 'app/pages/common/Navigation';
5+
import { useSignals } from 'app/store';
56

67
import { Container } from './elements';
78
import Prompt from './Prompt';
89

9-
const CLI = ({
10-
authToken,
11-
error,
12-
isLoadingCLI,
13-
signals: { cliMounted, signInCliClicked },
14-
user,
15-
}) => {
10+
const CLI = ({ authToken, error, isLoadingCLI, user }) => {
11+
const { cliMounted, signInCliClicked } = useSignals();
12+
1613
useEffect(() => {
1714
cliMounted();
1815
}, [cliMounted]);
@@ -32,4 +29,4 @@ const CLI = ({
3229
);
3330
};
3431

35-
export default inject('store', 'signals')(observer(CLI));
32+
export default observer(CLI);

packages/app/src/app/pages/CliInstructions/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
22
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
3-
import { inject } from 'mobx-react';
43
import React, { useEffect } from 'react';
54

65
import Navigation from 'app/pages/common/Navigation';
76
import SubTitle from 'app/components/SubTitle';
87
import Title from 'app/components/Title';
8+
import { useSignals } from 'app/store';
99

1010
import { Container, Content, Code } from './elements';
1111

12-
const CLIInstructions = ({ signals: { cliInstructionsMounted } }) => {
12+
const CLIInstructions = () => {
13+
const { cliInstructionsMounted } = useSignals();
14+
1315
useEffect(() => {
1416
cliInstructionsMounted();
1517
}, [cliInstructionsMounted]);
@@ -41,4 +43,4 @@ const CLIInstructions = ({ signals: { cliInstructionsMounted } }) => {
4143
);
4244
};
4345

44-
export default inject(['signals'])(CLIInstructions);
46+
export default CLIInstructions;

packages/app/src/app/pages/GitHub/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import {
66
protocolAndHost,
77
gitHubRepoPattern,
88
} from '@codesandbox/common/lib/utils/url-generator';
9-
import { inject } from 'mobx-react';
109
import React, { useCallback, useEffect, useState } from 'react';
1110

1211
import Navigation from 'app/pages/common/Navigation';
1312
import Title from 'app/components/Title';
1413
import SubTitle from 'app/components/SubTitle';
14+
import { useSignals } from 'app/store';
1515

1616
import {
1717
Container,
@@ -25,7 +25,9 @@ import {
2525
const getFullGitHubUrl = url =>
2626
`${protocolAndHost()}${gitHubToSandboxUrl(url)}`;
2727

28-
const GitHub = ({ signals: { githubPageMounted } }) => {
28+
const GitHub = () => {
29+
const { githubPageMounted } = useSignals();
30+
2931
const [error, setError] = useState(null);
3032
const [transformedUrl, setTransformedUrl] = useState('');
3133
const [url, setUrl] = useState('');
@@ -106,4 +108,4 @@ const GitHub = ({ signals: { githubPageMounted } }) => {
106108
);
107109
};
108110

109-
export default inject(['signals'])(GitHub);
111+
export default GitHub;

packages/app/src/app/pages/NewSandbox/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Centered from '@codesandbox/common/lib/components/flex/Centered';
22
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
33
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
44
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
5-
import { inject } from 'mobx-react';
65
import React, { useEffect } from 'react';
76

87
import Navigation from 'app/pages/common/Navigation';
8+
import { useSignals } from 'app/store';
99
import history from 'app/utils/history';
1010

1111
import NewSandboxModal from '../Dashboard/Content/CreateNewSandbox/Modal';
@@ -14,7 +14,9 @@ const createSandbox = template => {
1414
history.push(sandboxUrl({ id: template.shortid }));
1515
};
1616

17-
const NewSandbox = ({ signals: { sandboxPageMounted } }) => {
17+
const NewSandbox = () => {
18+
const { sandboxPageMounted } = useSignals();
19+
1820
useEffect(() => {
1921
sandboxPageMounted();
2022
}, [sandboxPageMounted]);
@@ -36,4 +38,4 @@ const NewSandbox = ({ signals: { sandboxPageMounted } }) => {
3638
);
3739
};
3840

39-
export default inject('signals')(NewSandbox);
41+
export default NewSandbox;

packages/app/src/app/pages/Search/index.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { inject } from 'mobx-react';
1+
import {
2+
ALGOLIA_API_KEY,
3+
ALGOLIA_APPLICATION_ID,
4+
ALGOLIA_DEFAULT_INDEX,
5+
} from '@codesandbox/common/lib/utils/config';
6+
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
7+
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
28
import qs from 'qs';
39
import React, { useCallback, useEffect, useRef, useState } from 'react';
410
import {
@@ -8,19 +14,12 @@ import {
814
Configure,
915
} from 'react-instantsearch/dom';
1016

11-
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
12-
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
13-
1417
import Navigation from 'app/pages/common/Navigation';
15-
import {
16-
ALGOLIA_API_KEY,
17-
ALGOLIA_APPLICATION_ID,
18-
ALGOLIA_DEFAULT_INDEX,
19-
} from '@codesandbox/common/lib/utils/config';
18+
import { useSignals } from 'app/store';
2019

2120
import 'instantsearch.css/themes/reset.css';
2221

23-
import { Container, Content, StyledTitle, Main } from './elements';
22+
import { Container, Content, Main, StyledTitle } from './elements';
2423
import Filters from './Filters';
2524
import Results from './Results';
2625
import Styles from './search';
@@ -32,7 +31,9 @@ const createURL = state => `?${qs.stringify(state)}`;
3231
const searchStateToUrl = (location, searchState) =>
3332
searchState ? `${location.pathname}${createURL(searchState)}` : '';
3433

35-
const Search = ({ history, location, signals }) => {
34+
const Search = ({ history, location }) => {
35+
const { searchMounted } = useSignals();
36+
3637
const [searchState, setSearchState] = useState(
3738
qs.parse(location.search.slice(1))
3839
);
@@ -43,8 +44,8 @@ const Search = ({ history, location, signals }) => {
4344
}, []);
4445

4546
useEffect(() => {
46-
signals.searchMounted();
47-
}, [signals]);
47+
searchMounted();
48+
}, [searchMounted]);
4849

4950
useEffect(() => {
5051
const unlisten = history.listen((loc, action) => {
@@ -115,4 +116,4 @@ const Search = ({ history, location, signals }) => {
115116
);
116117
};
117118

118-
export default inject('signals')(Search);
119+
export default Search;

0 commit comments

Comments
 (0)