Redux代码片段

文章目录

    • 一.redux单行
      • 1.`redux`
      • 2.`rxconst`
    • 二.redux多行
      • 3.`rxaction`
      • 4.`rxreducer`
      • 5.`rcredux`
      • 6.`rcreduxp`
      • 7.`rfcredux`
      • 8.`rfcreduxp`
      • 9.`reduxmap`
      • 10.`hocredux`

前言:利用插件的代码片段、简化Rudeux编写
在这里插入图片描述

一.redux单行

1.redux

import {
      connect } from 'react-redux

2.rxconst

export const constantName = 'constantName'

二.redux多行

3.rxaction

export const actionName = (payload) => ({
     
    type: type,
    payload
})

4.rxreducer

const initialState = {
     

}

export default (state = initialState, {
       type, payload }) => {
     
    switch (type) {
     

    case typeName:
        return {
      ...state, ...payload }

    default:
        return state
    }
}

5.rcredux

import React, {
      Component } from 'react'
import {
      connect } from 'react-redux'

export class index extends Component {
     
    render() {
     
        return (
            <div>
                
            </div>
        )
    }
}

const mapStateToProps = (state) => ({
     
    
})

const mapDispatchToProps = {
     
    
}

export default connect(mapStateToProps, mapDispatchToProps)(index)

6.rcreduxp

import React, {
      Component } from 'react'
import PropTypes from 'prop-types'
import {
      connect } from 'react-redux'

export class index extends Component {
     
    static propTypes = {
     
        prop: PropTypes
    }

    render() {
     
        return (
            <div>
                
            </div>
        )
    }
}

const mapStateToProps = (state) => ({
     
    
})

const mapDispatchToProps = {
     
    
}

export default connect(mapStateToProps, mapDispatchToProps)(index)

7.rfcredux

import React from 'react'
import {
      connect } from 'react-redux'

export const index = (props) => {
     
    return (
        <div>
            
        </div>
    )
}

const mapStateToProps = (state) => ({
     
    
})

const mapDispatchToProps = {
     
    
}

export default connect(mapStateToProps, mapDispatchToProps)(index)

8.rfcreduxp

import React from 'react'
import PropTypes from 'prop-types'
import {
      connect } from 'react-redux'

export const index = (props) => {
     
    return (
        <div>
            
        </div>
    )
}

index.propTypes = {
     
    props: PropTypes
}

const mapStateToProps = (state) => ({
     
    
})

const mapDispatchToProps = {
     
    
}

export default connect(mapStateToProps, mapDispatchToProps)(index)

9.reduxmap

const mapStateToProps = (state) => ({
     
    
})

const mapDispatchToProps = {
     
    
}

10.hocredux

import React from 'react'
import PropTypes from 'prop-types'
import {
      connect } from 'react-redux'

export const mapStateToProps = state => ({
     

})

export const mapDispatchToProps = {
     
 
}

export const hocComponentName = (WrappedComponent) => {
     
    const hocComponent = ({
       ...props }) => <WrappedComponent {
     ...props} />

    hocComponent.propTypes = {
     
    }

    return hocComponent
}

export default WrapperComponent => connect(mapStateToProps, mapDispatchToProps)(hocComponentName(WrapperComponent))

你可能感兴趣的:(React,react.js)