Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
final-exam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
final-exam
Commits
dc829dd5
Commit
dc829dd5
authored
Oct 06, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: products preview can empty when switch to another page and come
back
parent
c1d781cb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
index.js
src/pages/index.js
+3
-2
No files found.
src/pages/index.js
View file @
dc829dd5
...
...
@@ -42,7 +42,9 @@ export default function Home() {
}
setAlgorithm
(
productRandom
);
}
},
[
products
]);
useEffect
(()
=>
{
// products filter for search and category
let
product_cache
=
!!
router
.
query
?.
q
&&
router
.
query
?.
q
?.
length
...
...
@@ -60,7 +62,7 @@ export default function Home() {
Number
(
products
[
pid
].
stock
)
>
0
);
setProductsFilter
(
product_cache
);
},
[
products
,
category
]);
},
[
products
,
category
,
algorithm
]);
// for user click cart button
async
function
onCart
(
id
,
isRemove
=
false
)
{
...
...
@@ -121,7 +123,6 @@ export default function Home() {
let
response
=
await
axios
.
get
(
"/api/product"
);
let
pd
=
{};
response
.
data
.
map
((
e
)
=>
(
pd
[
e
.
id
]
=
e
));
setProducts
(
pd
);
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment