kristofdombi / react-with-breakpoints Goto Github PK
View Code? Open in Web Editor NEW๐ฌ ๐ a set of utility components for altering the user experience between breakpoints
License: MIT License
๐ฌ ๐ a set of utility components for altering the user experience between breakpoints
License: MIT License
To resolve, I had to change my import to reference the min.js file after updating to 4.0.1
import { BreakpointsProvider } from "react-with-breakpoints/dist/react-with-breakpoints.min.js";
instead of:
import { BreakpointsProvider } from "react-with-breakpoints";
Rolling back to 4.0.0 resolved this too. Briefly comparing the two versions revealed a difference in the file naming where 4.0.0 had the react-with-breakpoints.umd.js
& react-with-breakpoints.es5.js
and 4.0.1 had react-with-breakpoints.min.js
& react-with-breakpoints.js
A fix would be much appreciated.
Hi @kristof0425, thank you for putting out this library! The design looks great, but I noticed that one can only specify three breakpoints: small, medium and large. I'm wondering your thoughts on making that object more flexible or allow overriding it from the props in ShowAt
and HideAt
?
In our app, we have a few more breakpoints for more granular behavior, as well as some custom breakpoints for certain pages and layouts. And I am not sure how to implement those with this library.
Thoughts?
When I install this package via npm, it is correctly installed into my node_modules. However, when I try to use it in my code via
import {ShowAt, HideAt} from 'react-with-breakpoints';
I get a Module not found
error. After having a look into the package.json of this module, I saw this line:
This makes npm look inside node_modules/react-with-breakpoints/dist/withBreakpoint.js
, the dist folder however only contains a react-with-breakpoints.js
. I believe this is what the main
Attribute in the package.json
should point to. Changing this locally resolved the issue for me. As a temporary solution until this is resolved, changing the import statement to
import { ShowAt, HideAt} from 'react-with-breakpoints/dist/react-with-breakpoints';
also works.
Hey there,
First off, this is a really helpful project. I'm pretty new to React, and after looking at some of the markup from the AirBnb site, I was a little bummed to learn that the ShowAt/HideAt feature wasn't built in to React, so I think it's awesome that you've created an open source replica.
Also, I noticed that they have an additional xlarge breakpoint at 1440px that isn't currently included in this project. I've forked and included it to match the nature of your existing code (as best I can tell). Whether you decide to include it or not, I'll still be using your handy project.
On large screens (with width higher than the large breakpoint), none of the if clauses in withBreakpoints.handleResize()
is entered. This leaves the currentBreakpoint
state empty so that ShowAt
will not show the passed component even when breakpoint: large
is set. As soon as one resizes the window to be slimmer than the large
breakpoint, the state is set correctly and it works, this is however not the behavior I would expect.
Do the HideAt
and ShowAt
components just show/hide the children (as the documentation suggests), or do they render/not render as the code suggests?
Probably it will cause a breaking change because it will only support React version 16.3
or above.
withBreakpoints
to be a context provider.HideAt
and ShowAt
to be context consumers.In useBreakpoint.ts, small and medium need "largeAndBelow" added. Currently, if you use "largeAndBelow", HideAt will disappear below 1024; however, the component will show back up when the size is 768 or below.
How to fire an event when breakpoint changes?
Can you implement something like>
// Media query breakpoints
const breakpoints = {
small: 468,
medium: 768,
large: 1024,
xlarge: Infinity,
};
<BreakpointsProvider
breakpoints={breakpoints}
onBreakpointChange={( breakpoint ) => {
// Logic here
}}>
{/* ... */}
</BreakpointsProvider>
Any plans for introducing debounce on the resize events to prevent lots of re-renders?
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.