Answer the question
In order to leave comments, you need to log in
Can you comment on the test in react?
Colleagues, hello!
I am looking for work on the react stack, and since there is no commercial experience on react, I do test ones for training. Latest post from aviasales. I understand that there is nothing particularly complicated in it, but I would still like to hear your opinion on the code and in general regarding the organization of folders and files, to find out what you would improve or change (not counting the addition of a state manager and tests).
Code
Demo
Thanks in advance, any feedback would be greatly appreciated.
Answer the question
In order to leave comments, you need to log in
1. I would like to see the use of redux in the project. react+redux is the most widely used stack in React development.
2. Why are all handlers and states in App and not in Main? How are you going to scale this mess? Move everything related only to Main to Main. In a good way, see point 1.
3. Too many functional components. Think about where you can replace them with classes with shouldComponentUpdate implemented or with PureComponent to remove unnecessary render calls for these components.
4.
Capitalizing resource paths is wrong.
5. Instead of:import Logo from 'images/Logo.png';
const StyledLogo = styled.img.attrs({
src: Logo,
alt: 'Aviasales'
})`
width: 60px;
height: 61px;
`;
const StyledLogo = styled.img`
width: 60px;
height: 61px;
`;
const Error = ({ text }) => (
<StyledError dangerouslySetInnerHTML={{__html: text}} />
);
let element;
if (error && !isLoading) {
element = <Error text={error} />;
}
if (!error && isLoading) {
element = <Loader />;
}
if (!error && !isLoading) {
element = (
<>
<Heading />
<Main
isCurrencyExchanging={isCurrencyExchanging}
activeCurrency={activeCurrency}
handleCurrencyChange={this.handleCurrencyChange}
ticketsFilteredByStops={ticketsFilteredByStops}
stops={stops}
handleStopsChange={this.handleStopsChange}
handleUncheckOther={this.handleUncheckOther}
/>
</>
);
}
return element;
if (isLoading) return <Loader />;
if (error) return <Error text={error} />;
return (
<>
<Heading />
<Main
isCurrencyExchanging={isCurrencyExchanging}
activeCurrency={activeCurrency}
handleCurrencyChange={this.handleCurrencyChange}
ticketsFilteredByStops={ticketsFilteredByStops}
stops={stops}
handleStopsChange={this.handleStopsChange}
handleUncheckOther={this.handleUncheckOther}
/>
</>
);
filterTickets = (tickets, stops) => {
return tickets.filter((ticket) => {
return values(stops).indexOf(ticket.stops) !== -1;
});
};
filterTickets = (tickets, stops) => tickets.filter(
ticket => values(stops).includes(ticket.stops),
);
componentsDidMount() {
// много кода
}
componentsDidMount() {
this.fetchSomeData();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question