React Native : Is it possible (/how) to pass props to a class of static functions? -
normally when passing props, 1 like:
var myclass = require('./myclass.js'); <myclass prop1={prop1} prop2={prop2} />
these available in this.props
scope of child component.
if have helper class has static functions in it. how pass props class? declaration simply
var myhelperclass = require('./myhelperclass.js');
the contents similar to
var myhelperclass = react.createclass({ getinitialstate: function(){ return null; }, statics: { functionone: function(string){ var returnobject = {}; // this.props.. return returnobject; }, }, render: function() {} });
for i've created initalise function call in componentdidmount passes of data , function references down helperclass i'm curious.
if myhelperclass
stores static functions , doesn't render anything, create own store
them.
here's how package api calls:
var api = { getallposts: function(token, daysago) { daysago = daysago || 0; var requestobj = { headers: { 'accept': 'application/json', 'content-type': 'application/json', 'authorization': 'bearer ' + token, 'host': 'api.producthunt.com' } }; return fetch('https://api.producthunt.com/v1/posts?days_ago=' + daysago, requestobj) .then(function(res) { return res.json(); }) }, }
this located in api.js
file, , contains object. call module.exports = api
@ end, , require
in components need it. in components, can call api.getallposts(this.state.token, this.state.daysago)
, pass in state/props please.
Comments
Post a Comment