How to use match.params for global const?


#1

I’m implementing Kurounin Pagination.
How can I use match.params to get ID from URL to query database?
The code is below:
(In this case I’m trying to send “eventId” from createContainer to const pagination, but it’s fail)

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import createReactClass from 'create-react-class';
import { Link } from 'react-router-dom';
import { Table, Alert, Button, FormGroup, FormControl, Row } from 'react-bootstrap';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { Events } from '../../api/events';
import { Registers } from '../../api/registers';
import { TotalAmount } from '../../api/registers';
import BootstrapPaginator from 'react-bootstrap-pagination';
import NumberFormat from 'react-number-format';
import Loading from '../../components/Loading';


const pagination = new Meteor.Pagination(Registers, {
    filters: {eventid: eventId},
    sort: {createdAt: 1},
    perPage: 10,
    reactive: true,
    debug: true,
});


class DSRegisters extends Component {       
    render() {
...........
}

DSRegisters.propTypes = {
    registers: PropTypes.arrayOf(PropTypes.object).isRequired,
    totalCount: PropTypes.number.isRequired,
    match: PropTypes.object.isRequired,
    history: PropTypes.object.isRequired,
    evnt: PropTypes.object,
    loading: PropTypes.bool.isRequired,
};

export default createContainer(({ match }) => {
    eventId = match.params._evntid;
    const subevent = Meteor.subscribe('events');

    return {
        loading: !pagination.ready(),
        evnt: Events.findOne(eventId),
        registers: pagination.getPage(),
        totalCount: Registers.find({ eventid: eventId }).count(),
    };
}, DSRegisters);

#2

I get it.
Just add regs: pagination.filters({eventid: eventId}),

export default createContainer(({ match }) => {
    eventId = match.params._evntid;
    const subevent = Meteor.subscribe('events');

    return {
        loading: !pagination.ready(),
        evnt: Events.findOne(eventId),
        registers: pagination.getPage(),
        regs: pagination.filters({eventid: eventId}), // return pagination with filtering
        totalCount: Registers.find({ eventid: eventId }).count(),
    };
}, DSRegisters);

More efficiency

componentDidMount() {
      pagination.filters({eventid: this.props.evnt._id});
}