Skip to content

Instantly share code, notes, and snippets.

View aliakakis's full-sized avatar

Antonios Liakakis aliakakis

View GitHub Profile
@aliakakis
aliakakis / query.js
Created April 22, 2024 15:19
Local state query for React Query
/*
const [storeData, setStoreData] = useStoreQuery();
setStoreData((prev) => ({ ...prev, user: 'jane', country: 'US' }));
*/
const useStoreQuery = () => {
const queryKey = ["storeQuery"];
const initialData: InitialStoreData = {
bookDetails: {},
};
@aliakakis
aliakakis / index.ts
Created December 8, 2022 09:28
Hook Validation for React
import {useRef} from 'react';
/* Usage
const [user, setUser] = useState({
username: '',
password: '',
});
const [isUsernameInvalid, usernameErrors] = useValidate(user.username, [isEmpty]);
/**
* Remove duplicate values from an array
* @param {[] | Object[]} obj - array of values or array of objects
* @param {string} [prop] prop - the property in the objects which will be used as a unique value
* @returns {[]}
*/
export const removeDuplicatesFromArray = (obj, prop) => {
return Object.values(obj.reduce((acc, cur) => {
return {
...acc,
@aliakakis
aliakakis / event-queue.js
Last active October 25, 2023 09:10
Event Queue
/* Example
const q = EventQueue({}); You can also use the 'new' keyword
q.enQueue(async () => {
// [CODE HERE]
});
OR
@aliakakis
aliakakis / match-media.js
Last active February 5, 2021 08:52
Vue based
export default {
name: "match-media",
props: {
mediaWidth: {
type: Array,
required: true
}
},
data() {
return {
@aliakakis
aliakakis / match-media.js
Last active December 4, 2018 07:50
React based
/*
## Example ##
<MatchMedia mediaWidth={["(min-width: 768px)", "(min-width: 1280px)"]}>
<Checkbox
id="check_1"
label="Hello World!"
checked={isChecked}
onChange={() => this.setState({ isChecked: !isChecked })}
@aliakakis
aliakakis / redraw.component.js
Last active October 18, 2017 10:52
React component that will redraw its children when there is a re-render thus resetting it
import React, {Component} from 'react';
import PropTypes from 'prop-types';
export default class Redraw extends Component {
constructor(props) {
super(props);
this.infoMessages = {
warning: 'You cannot use Redraw to return an array of children in v.15.x.x',
};
import React, {Component, PropTypes} from 'react';
export const EnhanceDecorator = (options) => (TargetComponent) => {
class EnhanceComponent extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
import React, {Component, PropTypes} from 'react';
import Animate from 'grommet/components/Animate';
export const RouteTransition = (options = {"animation": "fade", "duration": 1000, "delay": 0}) => (TargetComponent) => {
class EnhanceComponent extends Component {
constructor(props) {
super(props);
}
render() {