MCPcopy
hub / github.com/kenberkeley/react-demo / componentWillMount

Method componentWillMount

src/components/Msg/MsgDetail.js:22–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20 }
21
22 componentWillMount() {
23 // P.S: 在 Vue Demo 中,数据都是直接从后端 API 中获取
24 // 而这里可以先直接从 state 中获取,获取不到才从服务器获取
25 // (强制刷新页面会导致 state 被清空)
26 let { msg: { msgs }, params: { msgId } } = this.props
27
28 let msg = msgs.filter(({ id }) => id === msgId)[0]
29 msg ? this.setState({ msg }) : this.fetchMsgFromAPI(msgId)
30 }
31
32 fetchMsgFromAPI (msgId) {
33 msgService.fetch({ msgId }).then(msg => {

Callers

nothing calls this directly

Calls 1

fetchMsgFromAPIMethod · 0.95

Tested by

no test coverage detected