You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
It definitely solves the prop-drilling problem, but there is a new one.
If I'm passing the item from one component to its children, I can guarantee that the item is not null.
constSwapWidget=({ id })=>{const[swapState]=useItem(swapsItemApi,id);if(!swapState){return<Placeholder/>;}return(<><SwapInfoswapState={swapState}/><>
)
}constSwapInfo=({swapState}: {swapState: SwapState}) =>{return<div>{swapState.from} ->{swapState.to}</div>}
With provider solution, you need always to check if there is an item in every child.
Or maybe I understand your idea a little bit wrong, and you want to render children conditionally if the item with id exist in kv.
I can guarantee that the item is not null
you need always to check if there is an item in every child
It's up to the user
If they want to pass it through props - they can useItem at top-level and pass it down through props
If they are using useItem(or useItemState or any other solution that takes item from KV) - yes, there's a chance that the item is null. Either handle it or add item! if you're 100% sure it's there
I believe this question is not related to the hook itself. The only difference between useItemState and useItem there is that you get an option to get the key from Context
Case
Currrently there's
useItemState
anduseItemApi
hooksBut I came up with an idea of a more unified and convenient hook
Solution
useItem(api, key)
hook that accepts all the entities -ListApi
,ItemApi
,MappingApi
,SelectionApi
<ItemProvider api={api} />
and supportuseItem(api)
to solve prop-drilling and get rid of IDsThe text was updated successfully, but these errors were encountered: