Verified Commit 548ad9b1 authored by Florent Chehab's avatar Florent Chehab
Browse files

feat(withNetworkWrapper): added warnings in dev

parent 04b08024
......@@ -3,6 +3,7 @@ import React, { useEffect } from "react";
import RequestParams from "../utils/api/RequestParams";
import Loading from "../components/common/Loading";
import useSingleApiData from "../hooks/wrappers/useSingleApiData";
import Counter from "../utils/counter";
/**
* Simple class to the standardize the way data is requested.
......@@ -121,6 +122,32 @@ export default function withNetworkWrapper(
newProps.api[propKey] = hook;
});
if (process.env.NODE_ENV !== "production") {
const newPropsKeys = parameters.map(p => p.addDataToProp);
newPropsKeys.push("api");
const duplicatedKeys = new Counter(
newPropsKeys
).getDuplicatedElements();
if (duplicatedKeys.length !== 0) {
// eslint-disable-next-line no-console
console.warn(
"Duplicated keys in withNetworkWrapper, this might result in inconsistencies.",
duplicatedKeys,
parameters
);
}
newPropsKeys.forEach(propKey => {
if (propKey in props) {
// eslint-disable-next-line no-console
console.warn(
`Props '${propKey}' already present in props. It's going to be overridden by the withNetworkWrapper HOC.`
);
}
});
}
// Magically re-add proptypes in dev to make we are not missing anything
if (process.env.NODE_ENV !== "production") {
// eslint-disable-next-line react/forbid-foreign-prop-types
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment