Idiomatic way to use npm package that is concerned with data retrieval in non-Redux React application?
I am using a private npm package in my React project. The npm package is concerned with data retrieval and not with UI. I am pointing this out since React is a UI library. My question is about how to use this package together with React in a way that is React idiomatic.
Here are the options that I see:
Create a custom provider and wrap my app with it?
<DataRetreivalProvider><App /></DataRetreivalProvider>
Create a wrapper for the npm package with JSX representations of the methods the npm package exposes, even though they have nothing to do with UI? I have seen some packages do this, like apolloclient with their <Query>. I don't know exactly how I would do this, as I fail to see the point of doing this, but I dunno.
return {
<Client host="127.0.0.1" port="1905">
<Application ...>
<Device ... />
</Application>
</Connection>
}
Create the objects (connection and application) in my App component and then pass the data as props to my other components?
// import dataretreival
// create dataretreival client
<App>
<Component1 client={client}>
<Component2 client={client}>
</App>
reactjs
add a comment |
I am using a private npm package in my React project. The npm package is concerned with data retrieval and not with UI. I am pointing this out since React is a UI library. My question is about how to use this package together with React in a way that is React idiomatic.
Here are the options that I see:
Create a custom provider and wrap my app with it?
<DataRetreivalProvider><App /></DataRetreivalProvider>
Create a wrapper for the npm package with JSX representations of the methods the npm package exposes, even though they have nothing to do with UI? I have seen some packages do this, like apolloclient with their <Query>. I don't know exactly how I would do this, as I fail to see the point of doing this, but I dunno.
return {
<Client host="127.0.0.1" port="1905">
<Application ...>
<Device ... />
</Application>
</Connection>
}
Create the objects (connection and application) in my App component and then pass the data as props to my other components?
// import dataretreival
// create dataretreival client
<App>
<Component1 client={client}>
<Component2 client={client}>
</App>
reactjs
add a comment |
I am using a private npm package in my React project. The npm package is concerned with data retrieval and not with UI. I am pointing this out since React is a UI library. My question is about how to use this package together with React in a way that is React idiomatic.
Here are the options that I see:
Create a custom provider and wrap my app with it?
<DataRetreivalProvider><App /></DataRetreivalProvider>
Create a wrapper for the npm package with JSX representations of the methods the npm package exposes, even though they have nothing to do with UI? I have seen some packages do this, like apolloclient with their <Query>. I don't know exactly how I would do this, as I fail to see the point of doing this, but I dunno.
return {
<Client host="127.0.0.1" port="1905">
<Application ...>
<Device ... />
</Application>
</Connection>
}
Create the objects (connection and application) in my App component and then pass the data as props to my other components?
// import dataretreival
// create dataretreival client
<App>
<Component1 client={client}>
<Component2 client={client}>
</App>
reactjs
I am using a private npm package in my React project. The npm package is concerned with data retrieval and not with UI. I am pointing this out since React is a UI library. My question is about how to use this package together with React in a way that is React idiomatic.
Here are the options that I see:
Create a custom provider and wrap my app with it?
<DataRetreivalProvider><App /></DataRetreivalProvider>
Create a wrapper for the npm package with JSX representations of the methods the npm package exposes, even though they have nothing to do with UI? I have seen some packages do this, like apolloclient with their <Query>. I don't know exactly how I would do this, as I fail to see the point of doing this, but I dunno.
return {
<Client host="127.0.0.1" port="1905">
<Application ...>
<Device ... />
</Application>
</Connection>
}
Create the objects (connection and application) in my App component and then pass the data as props to my other components?
// import dataretreival
// create dataretreival client
<App>
<Component1 client={client}>
<Component2 client={client}>
</App>
reactjs
reactjs
asked Nov 27 '18 at 14:26
user1283776user1283776
3,5062158113
3,5062158113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
As I see it, even if your package is not concerned with UI, since it has to serve it to the components, at least should be concerned with React's lifecycle.
The Context API seems like the ideal fit, would pretty much be your first option, with Context Consumers wrapping other components, more or less like your third option.
For why wrap it like in your second, there are a lots of reasons (easy configuration, can be changed through state), but since it's a private package you may not be concerned with any, depends on what you do there really.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53501883%2fidiomatic-way-to-use-npm-package-that-is-concerned-with-data-retrieval-in-non-re%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As I see it, even if your package is not concerned with UI, since it has to serve it to the components, at least should be concerned with React's lifecycle.
The Context API seems like the ideal fit, would pretty much be your first option, with Context Consumers wrapping other components, more or less like your third option.
For why wrap it like in your second, there are a lots of reasons (easy configuration, can be changed through state), but since it's a private package you may not be concerned with any, depends on what you do there really.
add a comment |
As I see it, even if your package is not concerned with UI, since it has to serve it to the components, at least should be concerned with React's lifecycle.
The Context API seems like the ideal fit, would pretty much be your first option, with Context Consumers wrapping other components, more or less like your third option.
For why wrap it like in your second, there are a lots of reasons (easy configuration, can be changed through state), but since it's a private package you may not be concerned with any, depends on what you do there really.
add a comment |
As I see it, even if your package is not concerned with UI, since it has to serve it to the components, at least should be concerned with React's lifecycle.
The Context API seems like the ideal fit, would pretty much be your first option, with Context Consumers wrapping other components, more or less like your third option.
For why wrap it like in your second, there are a lots of reasons (easy configuration, can be changed through state), but since it's a private package you may not be concerned with any, depends on what you do there really.
As I see it, even if your package is not concerned with UI, since it has to serve it to the components, at least should be concerned with React's lifecycle.
The Context API seems like the ideal fit, would pretty much be your first option, with Context Consumers wrapping other components, more or less like your third option.
For why wrap it like in your second, there are a lots of reasons (easy configuration, can be changed through state), but since it's a private package you may not be concerned with any, depends on what you do there really.
answered Nov 27 '18 at 14:37
Diego NosiDiego Nosi
565
565
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53501883%2fidiomatic-way-to-use-npm-package-that-is-concerned-with-data-retrieval-in-non-re%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown