Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Rafajrg21
Copy link

Proposed Changes

Added new hook, usePreview.

Types of changes

  • [ x ] New feature (non-breaking change which adds functionality)

Checklist:

  • [ x ] My code follows the code style of this project.
  • [ x ] My change requires a change to the documentation.
  • [ x ] I have updated the documentation accordingly.
  • [ x ] I have read the CONTRIBUTING document.

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.

@@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [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();
Copy link
Owner

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.

Suggested change
const { viewport } = useViewport();
const { device } = useViewport();

const Screen = () => {
const { viewport } = useViewport();
/*
Using Object destructuring we can get width and device
Copy link
Owner

@aromalanil aromalanil Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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';
Copy link
Owner

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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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.
Copy link
Owner

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 };
Copy link
Owner

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

Suggested change
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({
Copy link
Owner

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.

@aromalanil
Copy link
Owner

@Rafajrg21 Thanks for the PR.
I have requested some changes, please make the necessary changes.

@aromalanil
Copy link
Owner

I think useMediaQuery will docs the same issue. Hence closing this PR.

@aromalanil aromalanil closed this Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants