Closed blntylmn closed 8 years ago
If you're using React, you can do:
componentDidMount() {
const Session = require('meteor/session');
// Do whatever you want with Session
}
I tried it but it complaint about there is no set function of Session
Session.set('test','something');
TypeError: Session.set is not a function
Try console log Session. You will see that Session is an object not a func. You can try Session.Session.set('test', 'something')
.
Thanks sammkj it works. But I feel something is not right
Everytime when I set a session variable I have to use this syntax :
const rv = require('meteor/session');
rv.Session.set('test','something');
and when get it this syntax :
const rv = require('meteor/session');
let variable=rv.Session.get('test');
//use variable
Must be a simple way but I am newbie in react :(
Could you suggest a proper and shorter way ?
I would create a helper function like:
function setSession(stuff) {
const Session = require('meteor/session').Session;
Session.set(stuff);
}
Then call that helper function anywhere in your react component. Hope that helps!
Yeap. Sometimes when you think complex you cab boot see the simple solutions :) Thats it. Thanks..
I'm getting this error when I try to
Is there a way to use Session with SSR ?