I am very new to Ramda and have got stuck in a problem. I need to get response from an api and pass it to next function but that same response needs to be used again at a later stage in the same compose. How can I save its value in that ramda func scope so it can be re-used again?
const getData = (req, ctx) => R.compose
(
R.andThen(... do some action using response from callSomeApi_2 and prop2)
, callSomeApi_2(req, ctx)
, R.andThen(R.map(R.prop('prop1'))) // response has prop1 and prop2 where prop2 is needed after getting response from callSomeApi_2
, callSomeApi_1(req, ctx)
);
How can this be achieved?
Have you tried to use R.props() instead of R.prop()
so the code becomes something like that :
const getData = (req, ctx) => R.compose
(
R.andThen(... do some action using response from callSomeApi_2 and prop2)
, callSomeApi_2(req, ctx)
, R.andThen(R.map(R.props('prop1', 'prop2'))) // this will include both properties 1 & 2
, callSomeApi_1(req, ctx)
);