Clicks and views #17
Merged
j285he
merged 0 commits from feat/clicks-and-views
into main
2 years ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'feat/clicks-and-views'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Analytics
componentAnalytics/index.tsx
andLink/index.tsx
tailwind.config.js
Things left to do:
Analytics/index.tsx
andLink/index.tsx
and get data from the given objectAdd(resolved Mar. 22)onClick={handleClick}
to the LinksLet's add all the
.vs/
files in the.gitignore
so others don't have to pull this downnit: Let's keep component names in TitleCase!
Delete this, there isn't a package.json at the very root level
Always use
const
when declaring variables, unless you have to perform direct mutation (which is rare), then uselet
Good job putting components in diff files, makes the main
Analytics
file cleaner!The intention was to declare the
viewCount
andclickCount
variables at the start of the component, and then mutate them in thefetch
function inside theuseEffect
(getting the actual view/click count from the returned json). I can't seem to directly declareconst
variables inuseEffect
and then use them. Should I uselet
or is there another way around this? Thanks!changed this line in version 2 of the diff
changed this line in version 2 of the diff
changed this line in version 2 of the diff
added 1 commit
Compare with previous version
added 3 commits
ab544fc7
- 1 commit from branchmain
Compare with previous version
changed the description
Hmmm so this approach wouldn't work. Direct mutation is generally avoided in React because it's most often a sign of bad practice. Since React only re-renders when state is changed, during the initial render, you will see 0 views and 0 clicks.
When you mutate
viewCount
andclickCount
, even though you've updated the variables, it won't trigger a re-render, so you'll still see 0 views and 0 clicks.Instead make both into state variables by using
useState
and use their appropriatesetState
functions on lines 14-16changed this line in version 4 of the diff
added 1 commit
Compare with previous version
added 1 commit
Compare with previous version
Gotcha, thanks!
resolved all threads
approved this merge request
Reviewers