【发布时间】:2019-12-05 18:04:08
【问题描述】:
所以,我基本上使用Github User API,通过Axios获取30个用户,并显示为列表,但我希望它只显示其中3个,怎么做?我应该尝试在地图功能或获取部分进行欺骗吗?
尝试在地图或过滤功能上做一些技巧,但以失败告终。
state = {
users: [],
loading: false,
alert: null
};
searchUser = async text => {
this.setState({ loading: true });
const res = await axios.get(
`https://api.github.com/search/users?q=${text}&client_id=${
process.env.REACT_APP_GITHUB_CLIENT_ID
}&client_secret=${process.env.REACT_APP_GITHUB_CLIENT_SECRET}`
);
this.setState({ users: res.data.items, loading: false });
};
{users.map(
<UserItem key={user.id} user={user} />
))}
【问题讨论】:
-
Github 提供了一个查询参数来限制每页。
per_page=3。 api.github.com/search/users?q=facebook&per_page=3。Array.slice也可以如下所述工作。
标签: arrays reactjs dictionary object