react-native-onyx icon indicating copy to clipboard operation
react-native-onyx copied to clipboard

[Improvement] Add the ability to join keys in withOnyx

Open arosiclair opened this issue 3 years ago • 0 comments

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.

arosiclair avatar Sep 13 '22 19:09 arosiclair