在简单的react组件下面会加载twits列表。 我使用“请求-承诺”包来获取数据。 首次通话效果很好(具有挂钩效果)。 问题是重新加载功能不起作用。
import React, {useState} from 'react'
import { tw } from './twitProxy'
//tw contains a simple promise request with twitter's api call.
function Twitter(){
let [twe, setTw] = useState()
React.useEffect(() => {
tw.then((data)=>{
setTw(JSON.parse(data))
})
}, [])
const reloadTwit = () => {
tw.then((data)=>{
console.log("reload twit without call api ? ")
setTw(JSON.parse(data))
})
}
return(
<div>
<ul>
{
(twe !== undefined) ?
twe.map((value, index) => {
return <li key={index}>{value.text}</li>
})
: console.log("loading")
}
<button onClick={reloadTwit}>Reload Twitter</button>
</ul>
</div>
)
}
export default Twitter