File tree Expand file tree Collapse file tree 2 files changed +37
-27
lines changed
Expand file tree Collapse file tree 2 files changed +37
-27
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import PropTypes from 'prop-types' ;
3- import styled , { ThemeProvider } from 'styled-components' ;
4- import { connect } from 'react-redux' ;
5- import { themeLight } from '../styles/themes/theme.light' ;
6- import { themeDark } from '../styles/themes/theme.dark' ;
2+ import styled from 'styled-components' ;
3+ import withThemeProvider from '../hoc/withThemeProvider' ;
74
85const StyledTitle = styled . h1 `
96 font-family: 'Karla', sans-serif;
@@ -15,26 +12,6 @@ const StyledTitle = styled.h1`
1512 margin: 0;
1613` ;
1714
18- export const Title = props => {
19- const { text, mode } = props ;
15+ export const Title = ( ) => < StyledTitle > JavaScript Design Patterns</ StyledTitle > ;
2016
21- return (
22- < ThemeProvider theme = { mode === 'dark' ? themeDark : themeLight } >
23- < StyledTitle > { text } </ StyledTitle >
24- </ ThemeProvider >
25- ) ;
26- } ;
27-
28- Title . propTypes = {
29- text : PropTypes . string . isRequired ,
30- mode : PropTypes . string . isRequired
31- } ;
32-
33- Title . defaultProps = {
34- text : 'JavaScript Design Patterns' ,
35- mode : 'dark'
36- } ;
37-
38- const mapStateToProps = ( { mode } ) => ( { mode } ) ;
39-
40- export default connect ( mapStateToProps ) ( Title ) ;
17+ export default withThemeProvider ( Title ) ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import PropTypes from 'prop-types' ;
3+ import { compose } from 'redux' ;
4+ import { connect } from 'react-redux' ;
5+ import { ThemeProvider } from 'styled-components' ;
6+ import { themeLight } from '../styles/themes/theme.light' ;
7+ import { themeDark } from '../styles/themes/theme.dark' ;
8+
9+ const withThemeProvider = Component => {
10+ const Sub = ( { mode } ) => (
11+ < ThemeProvider theme = { mode === 'dark' ? themeDark : themeLight } >
12+ < Component />
13+ </ ThemeProvider >
14+ ) ;
15+
16+ Sub . propTypes = {
17+ mode : PropTypes . string . isRequired
18+ } ;
19+
20+ return Sub ;
21+ } ;
22+
23+ const mapStateToProps = ( { mode } ) => ( { mode } ) ;
24+
25+ const composedWrapper = compose (
26+ connect (
27+ mapStateToProps ,
28+ null
29+ ) ,
30+ withThemeProvider
31+ ) ;
32+
33+ export default composedWrapper ;
You can’t perform that action at this time.
0 commit comments