This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ToastContext = React.createContext(null); | |
let id = 1; | |
const ToastProvider = ({ children }) => { | |
const [toasts, setToasts] = useState([]); | |
const addToast = useCallback(content => { | |
setToasts(toasts => [ | |
...toasts, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ToastProvider = ({ children }) => { | |
// ... | |
const addToast = useCallback(content => { | |
setToasts(toasts => [ | |
...toasts, | |
{ id: id++, content } | |
]); | |
}, [setToasts]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let id = 0; | |
const ToastProvider = ({ children }) => { | |
// ... | |
const addToast = useCallback(content => { | |
setToasts(toasts => [ | |
...toasts, | |
{ id: id++, content } | |
]); | |
}, [setToasts]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ToastProvider = ({ children }) => { | |
const [toasts, setToasts] = useState([]); | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Wrapper = styled.div` | |
position: absolute; | |
/* Top right corner */ | |
right: 0; | |
top: 0; | |
`; | |
const ToastContainer = ({ toasts }) => { | |
return createPortal( | |
<Wrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Wrapper = styled.div` | |
margin-right: 16px; | |
margin-top: 16px; | |
width: 200px; | |
position: relative; | |
padding: 16px; | |
border: 1px solid #d7d7d7; | |
border-radius: 3px; | |
background: white; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let title = title.replace(new RegExp(search, 'ig'), `<strong>$&</strong>`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(function (req, res, next) { | |
if (req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production') { | |
const secureUrl = 'https://' + req.hostname + req.originalUrl | |
res.redirect(302, secureUrl) | |
} | |
next() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class EndlessRecyclerViewScrollListener extends RecyclerView.OnScrollListener { | |
// The minimum amount of items to have below your current scroll position | |
// before loading more. | |
private int visibleThreshold = 5; | |
// The current offset index of data you have loaded | |
private int currentPage = 1; | |
// The total number of items in the dataset after the last load | |
private int previousTotalItemCount = 0; | |
// True if we are still waiting for the last set of data to load. | |
private boolean loading = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StoreManager extends React.Component { | |
constructor(props){ | |
super(props) | |
} | |
componentWillReceiveProps(newProps){ | |
if(newProps.hash !== this.props.hash){ | |
newProps.onUpdate() | |
} | |
} |