Comments (11)
Thanks for writing react-cookie! It's been very helpful on the client side.
I'm trying to figure out how to use it on the server side. What does plugToRequest()
do? The readme doesn't say. "You can also plug it directly" - I don't understand what that means. Plug what into what?
Also, does "(require the cookieParser middleware)" mean that we need to use cookieParser in order for plugToRequest()
to do whatever it does? What's the point of plugToRequest
if we can just read the cookie from the request on the server side thanks to cookieParser?
I guess a more complete example that showed what you do after calling plugToRequest
, or what it enables you do do, would be helpful.
from cookies.
Try
reactCookie.setRawCookie(req.headers.cookie);
let user = reactCookie.load('username-session');
from cookies.
@jonathan-stone just took the time to improve the readme
plugToRequest is loading your user cookies so you can do server-rendering and have the same result. Everytime you load a cookie, it will simulate the same result on Node.js.
It also send back the changes you might have done while server-rendering (setting or removing a cookie).
from cookies.
Thanks @eXon !
from cookies.
I decided to create custom middleware because of this stackoverflow answer: http://stackoverflow.com/questions/34038726/redux-router-how-to-replay-state-after-refresh
from cookies.
Are you using plugToRequest
? (look at the readme)
from cookies.
I am but when I do const userId = cookie.load('userId')
I get undefined.
from cookies.
I resolved this problem like this:
mz026/universal-redux-template#35
from cookies.
Hi @eXon, to clarify, this issue is a request for improved documentation. I'm curious, why it has been closed with no change to the docs? I guess I'm being lazy in that I could read the source and file a PR with a little more info in the documentation source.
@developer239, I did something similar, but I wonder if react-cookie would have made adding that code unnecessary.
from cookies.
@jonathan-stone are you saying the plugToRequest
is broken? Because how to use it is kinda the first thing explained in the readme.
from cookies.
@eXon No, I'm not saying anything like that. My question is just:
What does plugToRequest
do?
Pourquoi est-ce que je voudrais appeler ce function? Qu'est-ce que ca fait? Le documentation dit seulement qu'on peut l'appeler, main ne dit rien de ce que fait le function, ou ce que je pourrais faire apres l'avoir appele.
from cookies.
Related Issues (20)
- Memory leak with v6 HOT 10
- Nuxt3 error: Cookie is not a constructor HOT 2
- Import errors in `universal-cookie` and `react-cookie` HOT 3
- Support passing options to useCookies? HOT 1
- Error when using UniversalCookie in the browser HOT 1
- useCookies check for Provider doesn't work
- Is `removeCookie` supposed to replace a cookie's value with a string `"undefined"`? HOT 1
- Inconsistent change listener for cookie removal HOT 1
- Cannot read a refreshed cookie HOT 2
- How to retrieve a Cookie's Max-Age HOT 2
- Cookie.get method errors with "TypeError: e is not a function" in production builds HOT 5
- Unable to leverage universal-cookie, react-cookie, and universal-cookie express with NodeNext module resolution HOT 6
- react-cookie types export for require is incorrect HOT 1
- Could not find a declaration file for module react-cookie error HOT 2
- CookiesProvider cannot be used as a JSX component. HOT 6
- Unexpected re-renders when the saved cookie is an object
- [DOC]: not clear if removecookie removes all of the cookies for a given key
- Unintended state change
- Unable to resolve path to module 'universal-cookie' after update to 7.2.0 HOT 1
- Cookie expiration trace problem in Chrome and Safari
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cookies.