react-native-onyx
react-native-onyx copied to clipboard
[Improvement] Add the ability to join keys in withOnyx
Problem Coming from this discussion.
It's not currently possible to subscribe to keys relationally. So to join one key to another key in a collection we must subscribe to the key and the entire collection and then find the linked key manually like this
class Component {
render() {
this.linkedKey = this.props.collectionB.find(itemB => itemB.ID === this.props.itemA.bID);
// ...
}
}
export default withOnyx({
itemA: {
key: 'ITEM_A_KEY',
},
collectionB: {
key: 'COLLECTION_B',
},
})(Component);
Solution
Add the ability to accomplish this join in withOnyx directly so we don't need to write search code to link two keys together.