Skip to content

Instantly share code, notes, and snippets.

@mucahitgurbuz
Created May 15, 2021 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mucahitgurbuz/b1fd2c936df981abbd97d9efc68ddd73 to your computer and use it in GitHub Desktop.
Save mucahitgurbuz/b1fd2c936df981abbd97d9efc68ddd73 to your computer and use it in GitHub Desktop.
A React Component after optimization with the recent changes
import React, { useEffect } from 'react';
import { Resource, resourceActions } from '@oplog/resource-redux';
import { useSelector, useDispatch } from 'react-redux';
import { ResourceType } from '../../models';
import { StoreState } from '../../models/state';
import { AddressTypeOutputDTO } from '../../services/swagger';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
export const HelloWorld: React.FC = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
const { label } = useParams();
const addressType: Resource<AddressTypeOutputDTO> = useSelector(
(state: StoreState) => state.resources[ResourceType.GetAddressType]
);
useEffect(() => {
dispatch(resourceActions.resourceRequested(ResourceType.GetAddressType, { AddressLabel: 'DemoAddress' }));
}, []);
const onUrlParamRequest = () => {
dispatch(resourceActions.resourceRequested(ResourceType.GetAddressType, { AddressLabel: label }));
};
return (
<div>
<span>URLParam: {label}</span>
<span onClick={onUrlParamRequest}>{t('AddressType')}:</span>
{addressType}
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment