score:3
This is the result of TSLint no-shadow
rule. It allows to avoid mistakes that result from unintentionally shadowed variables. And it requires to provide workarounds for variables that could be safely shadowed.
Here addTodo
import is shadowed by addTodo
prop. It seems this was intentional, the rule is an obstacle in this case.
Such problems with no-shadow
can be avoided by enforcing a style where objects aren't destructured if variables may become ambiguous. This allows to resolve common problems with similarly named properties, e.g. in props
and state
objects. This also can improve the readability in some places because no backtracking is needed, while other places may become more verbose:
import * as actions from "../../redux/actions";
// ... component code
handleAdd = (todo: Todo) => {
const { props } = this;
// some code ... eventually:
props.addTodo(todo);
}
export default connect(
mapStateToProps,
{ addTodo: actions.addTodo }
)(MyComponent);
For multiple action creators as props, some pick
implementation could be used instead of { addTodo: actions.addTodo }
.
This style may be in conflict with ESLint prefer-destructuring
rule.
Source: stackoverflow.com
Related Query
- Search filter by name and date in React Redux Typescript
- Typing redux forms v7 with TypeScript and React
- Connecting a component with OwnProps using react redux and typescript in the .NET Core 2.0 reactredux template project
- Shadowed name in TypeScript and React-Redux
- React lazy with TypeScript and Redux
- React observable epic with Redux Toolkit and Typescript
- How to Save Page Name and URL in React to Redux store at each Load
- React component can't find redux store props and actions after migration to Typescript
- typescript react redux and redux-thunk using actionType as property in child component
- Why do we have interfaces and initialstates in React and typescript for Redux tool kit?
- Trying to Call Multiple ActionCreators in Component using React Redux and Typescript
- Programmatic React Router navigation with TypeScript and Redux in class component
- Typescript and React without modules - cannot find name 'React'
- TypeScript and React - children type?
- Difference between component and container in react redux
- React / Redux and Multilingual (Internationalization) Apps - Architecture
- Extending HTML elements in React and TypeScript while preserving props
- How to define css variables in style attribute in React and typescript
- Typescript types for React checkbox events and handlers?
- interface states and props in typescript react
- React - useRef with TypeScript and functional component
- Specify specific props and accept general HTML props in Typescript React App
- React HOC and TypeScript 3.2
- Typescript and React setting initial state with empty typed array
- Cannot read property '.then' of undefined when testing async action creators with redux and react
- Using compose() and connect() together in React JS redux
- Dealing with local state in react and redux
- Only allow specific components as children in React and Typescript
- Fractal Project Structure with React and Redux - pros/cons
- Calling an action from a different reducer with React and redux
More Query from same tag
- mapStateToProps and variable is not defined React-Redux
- React event fire when go to next input
- How do I unmount only one of the children in this.props.children
- React - API call with Axios, how to bind an onClick event with an API Call
- Dockerizing React App but ERR_EMPTY_RESPONSE
- how to assign each block an Id to differentiate between blocks inside a canvas and fetch data according to that id
- How to show a image in React from a JSON file
- TypeScript Type for HTML Element Tag
- Prevent image resizing in bootstrap Card
- child component dialog box not closing
- How to extract hashtags in URL?
- How to disable NGINX logging with file
- Passing intermediate data between promises in JS without using Promise.all and Promise.resolve
- GraphQL mutation not being sent to request when using Apollo client?
- Cannot read property 'state' of undefined in one place and in another it can read
- Mapping and Reducing an Array within an Array of Objects in Javascript
- React Hooks - Preventing child components from rendering
- How to create Material-UI nested style object from array using map in React
- React JSX expression for className is not evaluated at runtime
- React - How to wait for component props
- Page in React renders before the clients permissions are checked
- How to scroll and expand an Accordion by onClick on an icon from a component?
- Play mp3 from cache without service worker using react-player
- Implementing React Awesome Slider
- JSX element type 'ReactElement<any> | null' is not a constructor function for JSX elements
- loop through array issue
- React hook error is returning an empty object
- Logic inside loop not working on ReactJs
- React JS: Calling two functions in an onClick event does not run functions
- React - Accessing inline created iframe elements