Reputation: 2039
My question is regarding this NodeJS + ReactJS application I am modifying. I was able to do some modifications, but given my limited React knowledge, I was not able to do the below. Here is the application on Gitub: https://github.com/nice-table/bitmex-scaled-orders
I am inside the file "src/modules/orders/OrderForm.js" and trying to access the "positions" data (which I suppose is handled in the file "src\modules\data\DataProvider.js"). That same position data is rendered in this file: "src/containers/Dashboard/PositionsTable.js"
How can I have the "positions" data accessible from the OrderForm file? The same data being rendered in the PositionsTable.js file.
Upvotes: 0
Views: 244
Reputation: 302
According to the code, OrderForm
component uses UISettingsContext.Consumer
and PositionsTable
uses DataContext.Consumer
, so if you want to pass positions
to the OrderForm
components, you'll have to combine those 2 consumers like this:
<UISettingsContext.Consumer>
{settingsData => (
<DataContext.Consumer>
{dataContext => (
<OrderForm
instrumentData={settingsData.getCurrentInstrumentData()}
currentInstrument={settingsData.currentInstrument}
positions={dataContext.getAllPositions()}
createOrders={createBulkOrders.doFetch}
/>
)}
</DataContext.Consumer>
)}
</UISettingsContext.Consumer>
Of course you'll have to modify OrderForm
component to accept a positions
props like this:
function OrderForm({ positions, currentInstrument, instrumentData, createOrders }) {
...
}
Upvotes: 1