Let's stop hardcoding our initial state and fetch it from the server instead.

In this lesson you will learn:

  • Set up basic data fetching
  • Leverage the afterCreate lifecycle hook to automatically run any setup logic a model instance needs to do after creation
export const Group = types
.model({
users: types.map(User)
})
.actions(self => ({
// lifecycle hook
afterCreate() {
self.load()
},
load: flow(function* load() {
const response = yield window.fetch(`http://localhost:3001/users`)
applySnapshot(self.users, yield response.json())
})
}))

[MST] Loading Data from the Server using lifecycle hook的更多相关文章

  1. [转帖]Loading Data into HAWQ

    Loading Data into HAWQ Leave a reply Loading data into the database is required to start using it bu ...

  2. Loading Data into HDFS

    How to use a PDI job to move a file into HDFS. Prerequisites In order to follow along with this how- ...

  3. 使用OGG"Loading data from file to Replicat"的方法应该注意的问题:replicat进程是前台进程

    使用OGG的 "Loading data from file to Replicat"的方法应该注意的问题:replicat进程是前台进程 因此.最好是在vncserver中调用该 ...

  4. OGG "Loading data from file to Replicat"table静态数据同步配置过程

    OGG "Loading data from file to Replicat"table静态数据同步配置过程 一个.mgr过程 GGSCI (lei1) 3> view p ...

  5. Retrieving data from a server

    A system includes a server and a controller embedded in a device. Both the server and the embedded c ...

  6. [React] Update State Based on Props using the Lifecycle Hook getDerivedStateFromProps in React16.3

    getDerivedStateFromProps is lifecycle hook introduced with React 16.3 and intended as a replacement ...

  7. [React] Capture values using the lifecycle hook getSnapshotBeforeUpdate in React 16.3

    getSnapshotBeforeUpdate is a lifecycle hook that was introduced with React 16.3. It is invoked right ...

  8. 6 ways to import data into SQL Server

    I’m going to go over some methods to import data from text files into SQL Server today. The particul ...

  9. Transfer data to SQL Server from SPC-Light with Excel macros

    公司的QA检测软件SPC-Light,需要从其中读取一些信息至SQL Server数据库,储存或是做其它分析. 先是在Excel的VBE的工具中,引入一个组件Microsoft ActiveX Dat ...

随机推荐

  1. 原生ajax的请求过程

    原生ajax的请求过程 创建全平台兼容的XMLHttpRequest对象: function getXHR(){ var xhr = null; if(window.XMLHttpRequest) { ...

  2. MgdDbg工具

    ArxDbg是可以查看AutoCAD内部数据结构的工具,可惜是C++的.从网上找到了一个.NET版本的MgdDbg,实现的功能与C++版本的差不多. 1.运行程序,你只要右键点击AutoCAD窗口,在 ...

  3. 为什么选性别会导致兴趣都选中-vue

    为什么选性别会导致兴趣都选中-vue <%@ page language="java" import="java.util.*" pageEncoding ...

  4. Session小案例-----简单购物车的使用

    Session小案例-----简单购物车的使用 同上篇一样,这里的处理请求和页面显示相同用的都是servlet. 功能实现例如以下: 1,显示站点的全部商品 2.用户点击购买后,可以记住用户选择的商品 ...

  5. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  6. Ubuntu 16.04 安装 Open Jdk

    sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-7-jdk

  7. ThinkPHP5.0框架开发--第8章 TP5.0 模型

    ThinkPHP5.0框架开发--第8章 TP5.0 模型 第8章 TP5.0 模型 ================================================= 今日学习 1. ...

  8. Tomcat学习(一)——使用Eclipse绑定Tomcat并发布应用

    1.下载Tomcat 官网地址:http://tomcat.apache.org/whichversion.html 2.目录结构 bin:脚本目录 启动脚本:startup.bat 停止脚本:shu ...

  9. HttpWebRequest WebExcepton: The remote server returned an error: (407) Proxy Authentication Required.

    1. Supply the credentials of the Currently Logged on User to the Proxy object similar to this: // Be ...

  10. asp.net core 与EFcore 入门

    什么是EFcore? Entity Framework (EF) Core 是轻量化.可扩展和跨平台版的常用 Entity Framework 数据访问技术,EF Core 可用作对象关系映射程序 ( ...