Skip to content

Commit

Permalink
feat(react-router): upgrade history into V6
Browse files Browse the repository at this point in the history
use useNavigate hook
  • Loading branch information
Francisco Moreno committed Jan 11, 2024
1 parent 63a795e commit 2b5c820
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/components/bottle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const MainSection = ({ title, description, value, border = true }) => (
</DetailContainer>
);

function Bottle({ find, deleteBootle, history, t }) {
function Bottle({ find, deleteBootle, t }) {
const divRef = useRef(null);
const query = new URLSearchParams(useLocation().search);
const bottle = find(query.get('id'));
Expand All @@ -125,7 +125,7 @@ function Bottle({ find, deleteBootle, history, t }) {

return (
<Detail ref={divRef} navigate={navigate}>
<CloseWrapper><Button onClick={() => history.push('/')} icon={<Close />} /></CloseWrapper>
<CloseWrapper><Button onClick={() => navigate('/')} icon={<Close />} /></CloseWrapper>
<MainSection title={name} description={appellationOfOrigin} value={selectCup({ color, type })} border={false} />
<Section title={<Trans i18nKey={`bottle.color.${color}`} />} description={<Trans i18nKey={`bottle.type.${type}`} />} value={`${price} ${t('currency')}`} />
<Section title={region} description={year} value={<Rate allowHalf disabled="true" value={rate} />} />
Expand All @@ -138,7 +138,7 @@ function Bottle({ find, deleteBootle, history, t }) {
<Buttons>
<Button
onClick={() => {
history.push(`/edit?id=${bottle.id}`);
navigate(`/edit?id=${bottle.id}`);
}}
shape="round"
style={{
Expand All @@ -161,7 +161,7 @@ function Bottle({ find, deleteBootle, history, t }) {
}}
onClick={() => {
deleteBootle(bottle);
history.push('/');
navigate('/');
}}
/>
</Buttons>
Expand Down
6 changes: 3 additions & 3 deletions src/components/new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const B = (f) => (g) => (x) => f(g(x));
const capitalized = (word) => word.charAt(0).toUpperCase() + word.slice(1);
const toCapitalized = (str) => str.split(' ').map(capitalized).join(' ');

function OtherBottle({ add, history, find }) {
function OtherBottle({ add, find }) {
const nameRef = useRef(null);
const navigate = useNavigate();
const query = new URLSearchParams(useLocation().search);
Expand All @@ -59,7 +59,7 @@ function OtherBottle({ add, history, find }) {
const onFinish = (form) => {
// eslint-disable-next-line no-underscore-dangle
B(add)(cleanObject)({ ...form, year: form.year.year(), _id: bottle._id, _rev: bottle._rev, id: bottle.id });
history.push('/');
navigate('/');
};

useEffect(() => {
Expand All @@ -68,7 +68,7 @@ function OtherBottle({ add, history, find }) {

return (
<NewBottle navigate={navigate}>
<CloseWrapper><Button onClick={() => history.push('/')} icon={<Close />} /></CloseWrapper>
<CloseWrapper><Button onClick={() => navigate('/')} icon={<Close />} /></CloseWrapper>
<Form
name="newBottle"
layout="vertical"
Expand Down

0 comments on commit 2b5c820

Please sign in to comment.