【问题标题】:React Suspense, how to get an update after initial render?React Suspense,如何在初始渲染后获得更新?
【发布时间】:2022-11-22 17:30:55
【问题描述】:

我无法弄清楚如何更新我的资源以重新呈现。

例如:

...Lazy import('./childComponent'

const resource = fetchData()

// Main component:
return (
<Suspense>
  <Item />
  <Item />
</ Suspense>
)

// Child component:
const data = resource.getItem.read() <--- How can I update this data? Normally this would be a useEffect dependancy rerendering the component, doing a new call to the API.

function handleDeleteItem(id){
  // Function to delete through API
}

return <Item />

谢谢!

【问题讨论】:

    标签: reactjs react-suspense


    【解决方案1】:

    我面临同样的问题,我不知道要更新其他组件的“数据”。

    【讨论】:

    • 添加这样的 cmets 作为答案,会让你被否决,你会失去你辛苦赚来的积分。将其添加为评论而不是答案。
    猜你喜欢
    • 2022-01-02
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    相关资源
    最近更新 更多