inmagik/react-rocketjump

rjList limitOffsetPaginationAdapter doesn't pass pagination down to `effect` with `useRunRj`

Closed this issue · 2 comments

Hi guys,
I bumped into a strange behaviour (I'm using v2.6.2) using RJ to cnnect to a REST api using axios.
I have a state defined as such:

import rjList, { limitOffsetPaginationAdapter } from 'react-rocketjump/plugins/list'

const DocumentsState = rj(
  rjList({
    pageSize: 50,
    pagination: limitOffsetPaginationAdapter,
  }),
  {
    name: 'documents',
    effect: (page, params) => {
      // this returns a <Promise> axios.get using parameters
      return getDocuments(page, params)
    },
    computed: {
      count: 'getCount',
      documents: 'getList',
    },
  }
)

Which I run using useRunRj

const [cose, actions] = useRunRj(
    DocumentsState,
    [{q: 'hi' }],
    shouldCleanBeforeRun,
)

basically no page params is passed to my function getDocuments, I only receive the {q: 'hi' } object defined in the useRunRj deps.

Can you help me?

You should provide the page params yourself cause the page depends on your UI.
Second the code you posted cause an infinite loop cause the deps are evaluated by their instance and in Javascript object literals produce always a new instance.

grazie @gffuma! And yes I skipped one passage to simplify the code given as example, sorry for the bad code snippet!