Skip to content

Commit

Permalink
Remove prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
markusjwetzel committed Jan 23, 2025
1 parent ff4537c commit 670026d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
"files": [
"dist"
],
"dependencies": {
"prop-types": "^15.7.2"
},
"devDependencies": {
"packsy": "0.2.2",
"react": "16.13.1"
"packsy": "0.2.4",
"react": "18.3.1"
},
"peerDependencies": {
"react": ">=16.8"
Expand Down
74 changes: 35 additions & 39 deletions src/Provider.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import React, { useRef, useState, useMemo, useCallback } from 'react';
import PropTypes from 'prop-types';
import StacksContext from './StacksContext';
import Timer from './Timer';

const propTypes = {
autoDismiss: PropTypes.number.isRequired,
// eslint-disable-next-line react/forbid-prop-types
stacks: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
};

// eslint-disable-next-line react/prop-types
function Provider({ autoDismiss, stacks: stacksConfig, children }) {
const incrementalId = useRef(0);

Expand Down Expand Up @@ -43,34 +36,39 @@ function Provider({ autoDismiss, stacks: stacksConfig, children }) {
});
}, []);

const push = useCallback((name, component, config) => {
if (!stacks[name]) {
throw new Error(`Unknown stack "${name}"`);
}

setStacks((prevStacks) => {
const stack = { ...prevStacks[name] };
const item = { component, config };

// increment identifier
incrementalId.current += 1;

const id = incrementalId.current;

stack[id] = item;

if (autoDismiss) {
stack[id].timer = new Timer(() => {
destroy(name, id);
}, autoDismiss);
}

return {
...prevStacks,
[name]: stack,
};
});
}, []);
const context = useMemo(
() => ({
push: (name, component, config) => {
if (!stacks[name]) {
throw new Error(`Unknown stack "${name}"`);
}

setStacks((prevStacks) => {
const stack = { ...prevStacks[name] };
const item = { component, config };

// increment identifier
incrementalId.current += 1;

const id = incrementalId.current;

stack[id] = item;

if (autoDismiss) {
stack[id].timer = new Timer(() => {
destroy(name, id);
}, autoDismiss);
}

return {
...prevStacks,
[name]: stack,
};
});
},
}),
[],
);

return (
<>
Expand Down Expand Up @@ -103,13 +101,11 @@ function Provider({ autoDismiss, stacks: stacksConfig, children }) {
</Stacks>
);
})}
<StacksContext.Provider value={{ push }}>
<StacksContext.Provider value={context}>
{children}
</StacksContext.Provider>
</>
);
}

Provider.propTypes = propTypes;

export default Provider;

0 comments on commit 670026d

Please sign in to comment.