Parametrizing regex in require.context()

In my react component, I was trying to retrieve a file based on a param passed into that e.g.

const Section = () => {
    const params = useParams();
    const sectionId = params.sectionId;
    const regex = new RegExp(`Section${sectionId}.json$`);

    const section =  require.context('../json', false, regex);

It fails though with __webpack_require__(...).context is not a function error because according to the webpack doc: The arguments passed to require.context must be literals!

So I ended up retrieving all files using a literal and then getting the one I need based on the param e.g.

const sections = require.context('../json', false, /Section[1-9].json$/);
const sectionKey = Object.keys(sections).filter(key => regex.test(key));
const section = sections[sectionKey];

I find such a solution rather inconvenient and potentially not scaling too well in case of large number of files.

What would be a correct approach to this issue?