-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom hook -> use-preview #39
Conversation
@@ -53,6 +53,7 @@ yarn add use-custom-hooks | |||
- [useGeoLocation](https://github.com/aromalanil/useCustomHooks/tree/master/docs#-usegeolocation) | |||
- [useLocalStorage](https://github.com/aromalanil/useCustomHooks/tree/master/docs#-uselocalstorage) | |||
- [useMousePosition](https://github.com/aromalanil/useCustomHooks/tree/master/docs#-usemouseposition) | |||
- [useViewport](https://github.com/aromalanil/useCustomHooks/tree/master/docs#-usepreview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [useViewport](https://github.com/aromalanil/useCustomHooks/tree/master/docs#-usepreview) | |
- [useViewport](https://github.com/aromalanil/useCustomHooks/tree/master/docs#-useviewport) |
import { useViewport, MOBILE, TABLET } from "use-custom-hooks"; | ||
|
||
const Screen = () => { | ||
const { viewport } = useViewport(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The viewport
is not in the object, I think you meant this.
const { viewport } = useViewport(); | |
const { device } = useViewport(); |
const Screen = () => { | ||
const { viewport } = useViewport(); | ||
/* | ||
Using Object destructuring we can get width and device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Object destructuring we can get width and device | |
Using Object destructuring we can get the width and device type |
* @constant | ||
* @type {string} | ||
*/ | ||
export const MOBILE = 'MOBILE'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants need not be exported
* Returns one of three possible values depending of the screen's current width. | ||
* | ||
* @param {number} width | ||
* @returns {*} The constant corresponding the screen size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @returns {*} The constant corresponding the screen size. | |
* @returns {String} The device type corresponding the screen size. |
* Custom useState hook which listens to resize events and | ||
* manage the viewport of the user's device. | ||
* | ||
* @returns {Object} viewport An object with the width of the user's viewport and the device type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should define the type of this object refer this code
}; | ||
}, []); | ||
|
||
return { viewport }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are returning a nested object here. Since viewport is an object you should change this
return { viewport }; | |
return viewport; |
* @returns {Object} viewport An object with the width of the user's viewport and the device type. | ||
*/ | ||
function useViewport() { | ||
const [viewport, setViewport] = useState({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only save width in the state. Change only the width on resizing. Also, find the device type in the return statement.
@Rafajrg21 Thanks for the PR. |
I think |
Proposed Changes
Added new hook, usePreview.
Types of changes
Checklist:
Further Comments
I didn't create a new Issue because I'm adding a hook as stated in #1. If I need to do something else, correct something or I missed a step, please let me know.