Welcome to my page!
I'm Omar, Frontend developer from ๐ช๐ฌ Cairo, Egypt, currently living in ๐ฑ๐ป Riga, Latvia.
omarzikry / ment Goto Github PK
View Code? Open in Web Editor NEWeCommerce and Blog site
eCommerce and Blog site
ment/src/components/UI/Carousel/Carousel.js
Line 133 in b9dc88b
through out the component you are looking up same variables repeatedly. that is not the best approach from a performance point of view.
one good approach is to de-structure your state at the top of the render and use these variables instead of looking up repeatedly
ex :
const {currentIndex, loading, images} = this.state;
I think this doesn't require a separate component it just passes props and the structure is fairly simple that it can be used directly in the Carousal
component directly.
the translateValue
calculates the translation value and set the state with it. on goToPrevSlide
you don't use it to set the translate value and use it on goToNextSlide
. so it is not very consistent.
1- i think you should unify the way you update your state to avoid confusion during maintenance.
2- considering the asyn nature of react setState
I suggest setting both currentIndex
& translateValue
in the same setState
call to make sure both are updated at the same time. the translateValue
should just calculate and return the value.
./src/components/UI/Card/Card.js
Module not found: Can't resolve '../../../assets/images/Arrow-Right.png' in 'C:\Projects\ment\src\components\UI\Card'
Module not found: Can't resolve '../../../assets/images/Arrow-UP-Right.png' in 'C:\Projects\ment\src\components\UI\Card'
try to avoid binding inside the render
. it is quite expensive when it comes to performance and memory.
an alternative option is to use inline arrow function
instead of
onClick ={this.handleClick.bind(this, arguments)}
you can do
onClick = {()=>{this.handleClick( arguments)}
this component is a bit over complicated for its functionality. it doesn't need to be a class component or have an internal state. i did a quick refactor. let me know what do you think?
import React from "react";
import classes from "./ActiveDots.css";
function ActiveDots(props) {
let { imagesNumber, currentIndex, callIndex } = props;
const dots = [];
for (let i = 0; i < imagesNumber; i++) {
dots.push(
<p
key={`dot-no-${i}`}
className={currentIndex === i ? classes.active : null}
onClick={() => {
callIndex(i);
}}
>
{i < 9 ? 0 : ""}
{i + 1}
</p>
);
}
return <div className={classes.dots}>{dots}</div>;
}
export default ActiveDots;
this component serves no purpose and just adds another nesting level that just adds unneeded level of complexity. you should just use the <NavLink/>
from react-router
never update state directly. you should use setState
to update state to make sure react knows about it and appropriate state is formed.
NEVER mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable.
setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value.
There is no guarantee of synchronous operation of calls to setState and calls may be batched for performance gains. setState() will always trigger a re-render unless conditional rendering logic is implemented in shouldComponentUpdate().
If mutable objects are being used and the logic cannot be implemented in shouldComponentUpdate(), calling setState() only when the new state differs from the previous state will avoid unnecessary re-renders.
why did you choose to go with inline styling here?
ment/src/components/UI/Card/Card.js
Line 7 in b9dc88b
this component is quite big and has a lot of logic for both states. This should be split into two components. one for each state. i think this would be better for readability and maintenance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.