Comments (2)
Somehow missed this issue and was not using React for quite some time at a previous employer. Though always open if someone pushes a proposed fix even if I don't have the focus/time at the moment. This should be addressed now that I am a good place to update this lib and work on React applications again for these updates to make sense as a time investment.
For first issue:
You cannot call useViewportSizes with no parameters, you get a compilation error.
This should be addressed with an update tonight or tomorrow.
For the second issue:
const [vpW, vpH, updateVpSizes] = useViewportSizes(); doSomething(vpW, vpH); // ignore updateVpSizes return; // Error will result because updateVpSizes is unused
You should be able to destructure this as const [vpw, vpH] = useViewportSizes();
without TS complaining as standard practice if you do not need to invoke updateVpSizes()
.
For further context of source of issues: to preserve the minimum possible file size without compilation this was written in JS by hand (not usual for me) and d.ts
is a little interesting; turns out you can override export default
just by providing multiple defs -- very non-standard in either JS or TS outside of d.ts
modules, but necessary since Type Inference/Control Flow is limited with types only annotated.
Considering how late this is I would not blame you if you've moved on to using another lib, but would like to comment in case it is useful for anyone else or if you find a need for this library again and thanks for reporting this. Going forward I will be sure to vet TS use-cases now that I have had much more experience and a bit more free time.
from use-viewport-sizes.
Working example on 0.5.1-beta.1
with Typescript project (also demo'ing destructure without triggering TS error) can be found @ https://codesandbox.io/s/tender-dirac-hgd6fe
from use-viewport-sizes.
Related Issues (10)
- No SSR Support. HOT 9
- Document new options interface and dimension param HOT 1
- Improve Examples and use new interface HOT 1
- Standard Import and Variable Function Causes Elements to Disappear on Basic Frontend
- Add Throttle Support and use as default input behavior HOT 5
- useLayoutEffect warning during SSR HOT 11
- Ability to pass a function which may prevent re-render of React Tree on viewport changes
- Add Typescript support
- Support individual dimension-tracking and new options interface HOT 2
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 use-viewport-sizes.