Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-redux-typescript

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-redux-typescript

Typings and helper for connect function of redux

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

connect-redux-typescript

It is Helper for better typescript coverage of redux connect function npm package

Usage

First, init helper function with your redux state and pass connect function

import {connectHelperInit} from 'connect-redux-typescript'
import {connect} from 'react-redux'
import {State} from './path/to/typeof/state'

export const connectHelper = connectHelperInit<State>(connect)

Use helper in every place you want to use connect function

...
import {connectHelper} from './path/to/connectHelper';

const {connect, propsGeneric} = connectHelper(
  (state) => state.example,
  {sayAction}
)

Pass typeof propsGeneric to type of your React component

export class ExampleComponent extends React.Component<typeof propsGeneric> {
  render() {
    const {sayText, asyncMessage} = this.props
    return (
      <div>
        You say: {sayText || 'nothing'} <hr />
        <button onClick={() => sayAction(value)}> Say Hello </button>
      </div>
    )
  }
}

Return connected component

export default connect(ExampleComponent)

Notes

If you want to pass own props to component, use this construction

interface OwnProps {
  field: string
}

const {connect, propsGeneric} = connectHelper(
  (state, props: OwnProps) => state.example,
  {sayAction}
)

If you use async actions like redux-thunk and you want to know what type action return, you have to use dispatch explicitly

...
    return (
      <div>
        You say: {sayText || 'nothing'}
        <hr />
        <button onClick={() => this.props.dispatch(sayAction(value)).then(value => alert(value))}> 
          Say Hello
        </button>
      </div>
    )

Keywords

FAQs

Package last updated on 16 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc