Created
May 15, 2021 11:13
-
-
Save mucahitgurbuz/dd46254183fbf9203f609656dc286171 to your computer and use it in GitHub Desktop.
A React Component before optimization with the recent changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Dispatch, useEffect } from 'react'; | |
import { Resource, resourceActions, resourceSelectors } from '@oplog/resource-redux'; | |
import { connect } from 'react-redux'; | |
import { ResourceType } from '../../models'; | |
import { StoreState } from '../../models/state'; | |
import { AddressTypeOutputDTO } from '../../services/swagger'; | |
import { InjectedIntl, injectIntl } from 'react-intl'; | |
import { RouteComponentProps, withRouter } from 'react-router-dom'; | |
interface IHelloWorld { | |
intl: InjectedIntl; | |
match: any; | |
getAddressType: (params: { AddressLabel: string }) => void; | |
addressType: Resource<AddressTypeOutputDTO>; | |
onUrlParamRequest: () => void; | |
} | |
const HelloWorld: React.FC<IHelloWorld> = ({ intl, match, getAddressType, addressType, onUrlParamRequest }) => { | |
useEffect(() => { | |
getAddressType({ AddressLabel: 'DemoAddress' }); | |
}, []); | |
return ( | |
<div> | |
<span>URLParam: {match.params.label}</span> | |
<span onClick={onUrlParamRequest}>{intl.messages['AddressType']}:</span> | |
{addressType} | |
</div> | |
); | |
}; | |
export function mapStateToProps(state: StoreState): Partial<IHelloWorld> { | |
return { | |
addressType: resourceSelectors.getResource(state.resources, ResourceType.GetAddressType), | |
}; | |
} | |
export function mapDispatchToProps( | |
dispatch: Dispatch<resourceActions.ResourceAction>, | |
routeProps: RouteComponentProps | |
): Partial<IHelloWorld> { | |
return { | |
getAddressType: params => { | |
dispatch(resourceActions.resourceRequested(ResourceType.GetAddressType, params)); | |
}, | |
onUrlParamRequest: () => { | |
dispatch( | |
resourceActions.resourceRequested(ResourceType.GetAddressType, { | |
AddressLabel: routeProps.match.params['label'], | |
}) | |
); | |
}, | |
}; | |
} | |
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(injectIntl(HelloWorld))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment