Skip to content

Commit 91ecea9

Browse files
MichaelDeBoeyCompuIves
authored andcommitted
πŸ”¨ Refactor ConnectionNotice to use hooks (codesandbox#1963)
Small example refactor showing how to use Cerebral with React Hooks
1 parent b1eeda4 commit 91ecea9

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/ConnectionNotice/index.js renamed to packages/app/src/app/pages/Sandbox/Editor/Workspace/ConnectionNotice/ConnectionNotice.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import { observer } from 'mobx-react-lite';
12
import React from 'react';
2-
import { inject, observer } from 'mobx-react';
3+
4+
import { useStore } from 'app/store';
35

46
import { Container } from './elements';
57

6-
function ConnectionNotice({ store }) {
8+
export const ConnectionNotice = observer(() => {
9+
const { connected } = useStore();
10+
711
return (
8-
!store.connected && (
12+
!connected && (
913
<Container>
1014
You{"'"}re not connected to the internet. You can still edit, but you
1115
cannot save. We recommend using the {"'"}Download{"'"} function to keep
1216
your changes.
1317
</Container>
1418
)
1519
);
16-
}
17-
18-
export default inject('store')(observer(ConnectionNotice));
20+
});

β€Žpackages/app/src/app/pages/Sandbox/Editor/Workspace/ConnectionNotice/elements.jsβ€Ž

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import styled, { css } from 'styled-components';
2+
3+
export const Container = styled.div`
4+
${({ theme }) => css`
5+
color: ${theme.red};
6+
background-color: ${theme.redBackground};
7+
padding: 1rem;
8+
font-size: 0.75rem;
9+
`}
10+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ConnectionNotice } from './ConnectionNotice';

0 commit comments

Comments
Β (0)