solkimicreb / react-easy-params Goto Github PK
View Code? Open in Web Editor NEW:link: Auto synchronize your state with the URL and LocalStorage.
License: MIT License
:link: Auto synchronize your state with the URL and LocalStorage.
License: MIT License
I'm finding the current path
array to be kinda awkward to use in my app. I'm more used to the simple old string path like /path
. Which is also the default format in a lot of places and libraries, like location.pathname
for example.
Please consider providing the path as a simple string.
It seems paths that start with /#
don't work (they aren't reflected in path
variable), and also they make params
not work either, so example.com/#path?param=value
has both path
and params
empty.
I like using /#
paths (instead of actual /path
) as they work across simplest of servers and protocols (file://).
Love this lib (and easy-state), can't wait for the unification/merger.
Hi there,
Just noticed today that this library doesn't seem to play nicely with empty url search query params.
For example, for the url:
http://localhost:5000/something?event=
I'm getting the following error:
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at toParams (es.es5.js:37)
at Object.../../node_modules/react-easy-params/dist/es.es5.js (es.es5.js:47)
at __webpack_require__ (bootstrap:709)
I'm actually not even using the params part of this library at the moment, just the storage part - but it seems to run some kind of setup for the params side of things in any case (I assume the backing stores). Looks like its running into some kind of JSON parsing error when a query param is empty in the url.
In this case I believe the params object should look like so:
{
event: "",
}
Using the popular query-string
library, I get an object like that when I parse the query param part of the url.
This kind of a continuation of the last one. Sorry for another issue ๐
So as mentioned in the last issue, I wasn't actually using the params side of this library - just the storage.
Would it be possible to provide an option to disable the params side of things? As right now, I'm getting behaviour like this (the params are auto-converting to types as clarified in the last issue):
something?event=
-> something?event=""
But in my current use-case, because I'm not actually using the params side of the library and the types it provides using the "
(quotations), my event
input is being filled with the empty ""
(double quotations).
I think there should be a way to disable / enable parts of the library, or each feature should perhaps be available through its own library... so maybe an extra one called react-easy-storage
? In my current use-case I'd be able to use that one and cut out the params side of things for now.
EDIT:
In actual fact, I kinda like what you're doing here:
key = encodeURIComponent(key)
value = encodeURIComponent(JSON.stringify(value))
and here:
const key = decodeURIComponent(keyValue[0])
const value = decodeURIComponent(keyValue[1])
try {
params[key] = JSON.parse(value)
} catch (err) {
params[key] = value
}
I guess that takes care of converting everything correctly and maintaining type information? I may just implement this in my current use-case as well, as I agree its quite nice to have that information. Then my code should be compatible - so its no biggy.
But perhaps still something to look into for people who do want to only opt in to a certain part of the library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.