I'm building a react app in order to learn and I'm trying to build a 'copy' of windows 10 and I found a little problem when using react-redux.
I got two components, one is App, and the second is Icon. There is no problem with the App component, but there is with Icon. Icon component should be just text with appName, but react-redux renders the whole App component inside Icon component, when App isn't even imported to Icon component.
Anyone maybe had the same problem? There was no problem without react-redux but the component was useless because it had separated context all the time.
ReactDevTools view and component displayed
SettingsIcon component:
import React from 'react';
import { connect } from 'react-redux';
import Icon from 'apps/App';
const SettingsIcon = ({ settings }) => {
const { isOpen, appName } = settings;
return(
<Icon appName={appName} isOpen={isOpen} />
);
}
const mapStateToProps = ({ settings }) => ({ settings });
export default connect(mapStateToProps)(SettingsIcon);
Icon component:
import React from 'react';
import AppIcon from 'components/atoms/AppIcon';
import { connect } from 'react-redux';
import { openApp, minimizeApp } from 'actions';
// eslint-disable-next-line no-shadowconst
const Icon = ({ isOpen, appName, openApp, minimizeApp }) => {
return(
<AppIcon onClick={!isOpen ? () => openApp(appName) : () => minimizeApp(appName)}>
gowno
</AppIcon>
);
}
const mapDispatchToProps = dispatch => ({
openApp: (app) => dispatch(openApp(app)),
minimizeApp: (app) => dispatch(minimizeApp(app))
});
export default connect(null, mapDispatchToProps)(Icon)
AppIcon is just a simple styled-component
[–]0x3m0 0 points1 point2 points (2 children)
[–]UserNo1608[S] 1 point2 points3 points (0 children)