Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add task solution #1686

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

add task solution #1686

wants to merge 3 commits into from

Conversation

dipinchuk
Copy link

Copy link

@anstsot anstsot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checklist #1 is not satisfied

src/App.tsx Outdated
Comment on lines 13 to 19
const [amount, setAmount] = useState(0);
const [color, setColor] = useState('');

<button type="button" data-cy="all-button">
Load all goods
</button>
useEffect(() => {
getGoods(amount, color)
.then(setGoods);
}, [amount, color]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove amount and color state variables. try to create 3 separate function by using useCallback

Copy link
Author

@dipinchuk dipinchuk Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don`t understand how to use it, can I just code it in useEffect?..

src/api/goods.ts Outdated
}

export const get5First = () => {
export const getGoods = (amount: number, color: string) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just create 2 separate functions: get5First and getRedGoods

src/App.tsx Outdated
Comment on lines 12 to 23
useEffect(() => {
if (selected5First) {
get5First()
.then(setGoods);
} else if (selectedRed) {
getRedGoods()
.then(setGoods);
} else {
getAll()
.then(setGoods);
}
}, [goods]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant here. Look, you can creat functions for each button and wrapped it on useCallback as Anastasia note in previous review. Or alternative You can create memoize value to prevent make request each time when you click on button, for example:
const allTodos = useMemo(() => getAll(), []) const firstFiveTodos= useMemo(() => get5First(), [])
The same for first 5 goods and red goods. And after that you can set this memoized values to state by clicking corresponding button

src/App.tsx Outdated
Comment on lines 9 to 10
const [selected5First, setSelected5First] = useState(false);
const [selectedRed, setSelectedRed] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant states

Copy link

@anstsot anstsot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, approving:sparkles:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants