0.4.2 • Published 3 years ago

lb-reacts v0.4.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

封装了项目目录结构的react项目

目录结构

├─components        
│  └─component1     
│          api.js   
│          locale.js
│          mock.js  
│          page.jsx 
│          page.less
│          store.js 
│
├─pages
│  └─page1
│      │  api.js    
│      │  locale.js
│      │  mock.js
│      │  page.jsx
│      │  page.less
│      │  route.js
│      │  store.js
│      │
│      └─page2
│              api.js
│              locale.js
│              mock.js
│              page.jsx
│              page.less
│              route.js
│              store.js

demo

import React from 'react'
import less from './page.less'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { renderRoutes } from 'react-router-config'
import * as page1Action from './store'
import { withTranslation } from 'react-i18next'

class page1 extends React.Component {
  constructor (props) {
    super(props)
  }

  render () {
    return (

          <div className={less.page1}>
            <button aria-label="Increment value" onClick={() => this.props.page1Action.increment()} >
            {this.props.t('pages.page1.name')}
            </button>
            <span>{this.props.page1State.value}</span>
            <button aria-label="Decrement value" onClick={() => this.props.page1Action.decrement()}>
            {this.props.t('pages.page1.name')}
            </button>
            <div>
              {renderRoutes(this.props.route.routes)}a
            </div>
          </div>

    )
  }
}

export default withTranslation()(
  connect(
    state => {
      return ({
        page1State: state.page1
      })
    },
    dispatch => ({
      page1Action: bindActionCreators(page1Action, dispatch)
    })
  )(page1)
)