by sunilsandhu · 8y ago · 0 comments
Additionally, you don't need to .bind on deleteItem since functions initialized as class properties are automatically bound (you should just be able to do deleteItem={() => this.deleteItem(key)}).
Another thing is that there are certain weird things that happen if you use the index as the key for ToDo's render function (consider using the actual item text itself): https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-p...
Overall, great article! Hope that's not too nitpicky!
Don’t do this. Arrow functions (and bind) are reallocated on every render, so this can result in a lot of useless re-renders.
Please see this post for clarification on the actual pros and cons of creating functions in `render`: https://cdb.reacttraining.com/react-inline-functions-and-per...
I consider this a code smell (b/c we had huge problems with it) and I usually give the advice to do it differently. There are exceptions, of course.
import { css } from 'emotion';
const WhateverComponent = () => (
<div className={css`
background-color: green;
height: 100%;
`} />
);
export default WhateverComponent;
...or... import styled from 'react-emotion';
const WhateverComponent = ({ className }) => (
<div className={className} />
);
export default styled(WhateverComponent)`
background-color: green;
height: 100%;
`;
...or... import styled from 'react-emotion';
const BigGreenBox = styled('div')`
background-color: green;
height: 100%;
`
const WhateverComponent = () => (
<BigGreenBox />
);
export default WhateverComponent;Please know this feedback is presented constructively. I had a bit of difficulty following if the example was Vue or React. One place under “How do we mutate data?”, the last word is Vue: followed by React code. Under “How do we pass data through to a child component?” both say “in React”. I’m very uncomfortable giving editorial advice to a stranger this way; it’s a great article and just wanted to trade some polish for the valuable information you shared. Thanks.
But seeing as you've asked, I prefer Vue at the moment as you can achieve the same things in React but with fewer lines of code :)