In my React component, I create some input fields based on some configuration object i.e.
[{ label: ‘Client ID’, id: ‘clientId’, placeholder: ‘Enter client ID, e.g. integration-client’, type: ‘text’, stateCallback: setClientId }, { label: ‘Client name’, id: ‘clientName’, placeholder: ‘Enter client name, e.g. Integration Client’, type: ‘text’, stateCallback: setClientName },...]
then, I map this array to jsx
const jsx = array.map(item => toJsx(item))
I wanted to extract the configuration object to different file so my component is not polluted with configuration boilerplate, but the issue is
stateCallback: setClientId
in the configuration object - I pass here references to React Hook's state methods from my component, which will be inaccessible in the new configuration file.
THE QUESTION: Is there a better way / pattern to extract such config from components? Any tips to solve my problem?
Aucun commentaire:
Enregistrer un commentaire