原始问题:https://github.com/acdlite/recompose/issues/232
如何访问BaseComponent的ref或任何级别的组件?
码:
class BaseComponent {
doSth(){...}
}
const Component compose(...some)(BaseComponent);
class App {
componentDidMount() {
// undefined(doSth) is not a function
this.refs.component.doSth();
}
render() {
<Component ref="component" />
}
}
Run Code Online (Sandbox Code Playgroud) 我试图将一些JS转换为Reason,沿着我需要键入JSON响应的方式,并检查对象中是否存在键.
这是我目前的代码:
let api_key = "";
let api_url = "http://ws.audioscrobbler.com/2.0";
let method = "user.getRecentTracks";
let user = "montogeek";
type trackAttr = {
nowplaying: bool
};
type artistT = {
text: string
}
type trackT = {
attr: trackAttr,
name: string,
artist: artistT
};
type recentTrackT = {
track: array(Js.Dict.t(trackT))
};
type response = {
recenttracks: recentTrackT
};
Js.Promise.(Fetch.fetch(api_url ++ "?method=" ++ method ++ "&" ++ user ++ "=" ++ user ++ "&limit=1&format=json&api_key=" ++ api_key)
|> then_(Fetch.Response.json)
|> then_(json: response => …Run Code Online (Sandbox Code Playgroud)