Skip to content

Conversation

@ksemya
Copy link

@ksemya ksemya commented Sep 6, 2019

No description provided.

import { Pockemon_card } from '../pockemon_card/Pockemon_card';
import './app_container.scss';

export function App_container(props) {

Choose a reason for hiding this comment

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

принято все же писать названия классов в CamelCase

return (
<header>
<Link to="/"><h1 className="text">Pokedex</h1></Link>
<Link to="/caught"><span className="text">Пойманные покемоны</span></Link>

Choose a reason for hiding this comment

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

вынеси все пути в константы

if (caught===null) return (<></>)
else return(
<>
{caught && <Catch_button onClick={this.handleCatchButton} disable={caught} text='Пойман' />}

Choose a reason for hiding this comment

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

почему бы не вынести определение, какой текст должен быть у кнопки из jsx и упростить рендер до
return caught === null ? null :
<CatchButton onClick={this.handleCatchButton} disable={caught} text={buttonText} />

console.log(error);
return (
<>
{!loading && !error && total===0 && <Empty_component />}

Choose a reason for hiding this comment

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

я бы все же переписал данный рендер хотя бы на тернарниках - в таком виде надо ещё посидеть и подумать, сколько различных вариантов рендера у компонента :D


componentDidMount(){
const {id} = this.props;
fetch(`http://localhost:3000/caught_pokemons/?id=${id}`, {

Choose a reason for hiding this comment

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

я бы посоветовал вынести запрос из компонента, и сделать несколько уровней абстракции - например создать apiService, в котором будет создаваться дефолтная конфигурация http запросов, и который будет предоставлять методы ( GET, PUT, POST и т.д.). И также создать pokemonsService, который уже будет предоставлять методы getCaughtPokemon(id) и который уже будет вызывать apiService.get('http://localhost:3000/caught_pokemons', queryParams)

const {name, img} = this.state;
return (
<>
{!name &&<Loading />}

Choose a reason for hiding this comment

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

в таких случаях лучше юзать тернарный оператор

return (
<>
{!loading && !error && total===0 && <Empty_component />}
{total>0 && <App_container onScroll={this.handleScroll} pokemons={pokemons} />}

Choose a reason for hiding this comment

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

насколько я вижу CaughtUnmounted и MainUnmounted почти идентичны - за исключением одной строчки в рендере CaughtUnmounted - почему бы не вынести рендер этой строки в родительский компонент и не сделать один компонент PokemonsListContainer, который в двух разных случая будет просто оборачиваться в два различных hoc connect?

Copy link
Author

Choose a reason for hiding this comment

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

Я думала, что стоит их разделить, потому что по смыслу это разные компоненты и может понадобиться изменить функционал одного независимо от другого.

}})
.then(response => {
if (response.ok) {
return Promise.resolve(response);

Choose a reason for hiding this comment

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

зачем promise.resolve и promise.reject? почему бы просто не написать return response и throw new Error(response.statusText)?

}
})
.then(response => response.json())
.then(data => {

Choose a reason for hiding this comment

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

вот этот блок я бы все же не выносил из компонента - он довольно жестко связан с его внутренней логикой и так становиться не очевидно что же может изменить стейт компонента

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.

2 participants