Home > front end >  Story - saga has been called the action
Story - saga has been called the action

Time:12-07

Saga. Js
 
The import {takeEvery, put} from 'story - saga/effects'
The import {GET_NAME_VALUE} from './actionTypes'
The import axios from 'axios'
The import {getName} from './actionCreators'



The function * fetchGetName (action) {
The console. The log (action)
Const res=yield axios. Get ('/test. The json)
Const name=res. Data. The name
Yield the put (getName (name))
}


* mySaga function () {
Yield takeEvery (GET_NAME_VALUE fetchGetName)
}

Export the default mySaga



Component
 
Import the React, {Component} from 'React'
The import store from '/store'
Import {getName} from './store/actionCreators'
Export the default class App extends Component {
The constructor (props) {
Super (props)

This. State=store. GetState ()
}

Render () {
Return (


)
}

//listen to the state in the store to change the page
ComponentDidMount () {
Store. The subscribe (()=& gt; Enclosing setState (store. GetState ()))
}

HandleGetName () {
Store. Dispatch (getName ())
}
}



See can in the console or redux tools have been calling the action
Why is this excuse me?
  • Related