1.0.0 • Published 11 days ago

@drtyhu8npm/placeat-doloremque-dolore v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

@drtyhu8npm/placeat-doloremque-dolore

Type safe and Zero-cost React library to work with higher-order component (HOC)

Documentation NPM version Build Typescript Bundle size Bundle dependency License

Getting Started

Read the docs

Install with npm

npm install @drtyhu8npm/placeat-doloremque-dolore

Or install with yarn

yarn add @drtyhu8npm/placeat-doloremque-dolore

Usage example

Hello World

import { withDefault, withOverride, withHocs } from "@drtyhu8npm/placeat-doloremque-dolore";

export const Hello = (() => {
  function Hello({ name }: { name: string }) {
    return <div>Hello {name}!</div>;
  }

  return withHocs([withDefault({ name: "World" })])(Hello);
})();

// <Hello /> is equivalent to <div>Hello World!</div>
// <Hello name="You" /> is equivalent to <div>Hello You!</div>

export const HelloYou = withOverride("name", "You")(Hello);

// <HelloYou /> is equivalent to <div>Hello You!</div>
// <HelloYou name="..." /> is a typescript error ❌

Example with react-query

Lets suppose you have the following code and then you need a query inside your App component

const queryClient = new QueryClient();

function App() {
  // Oops... ❌
  // This is an error because App is not wrapped by QueryClientProvider
  const query = useQuery({...});

  return (
    <QueryClientProvider client={queryClient}>
      <>...</>
    </QueryClientProvider>
  );
}

export default App;

Using @drtyhu8npm/placeat-doloremque-dolore, you can easily fix this with:

import {withWrapper, withOverride} from "@drtyhu8npm/placeat-doloremque-dolore";

const queryClient = new QueryClient();

function App() {
  // ✅
  const query = useQuery({...});

  return (
    <>...</>
  );
}

export default withWrapper(
  withOverride({ client: queryClient })(QueryClientProvider)
)(App);

// for didactic purpose, the following code could also be applied
// const MyQueryClientProvider = withOverride({ client: queryClient })(QueryClientProvider)
// export default withWrapper(MyQueryClientProvider)(App);

Using IIFE

import { withWrapper, withOverride, withHocs } from "@drtyhu8npm/placeat-doloremque-dolore";

const queryClient = new QueryClient();

const App = (() => {
  function App() {
    // ✅
    const query = useQuery({...});

    return <>...</>;
  }

  return withHocs([
    withWrapper(withOverride({ client: queryClient })(QueryClientProvider)),
  ])(App);
})();

export default App;

Clock

Check out an entire project with @drtyhu8npm/placeat-doloremque-dolore, see the demo and try to imagine creating a reusable component with the same flexibility

Take a look on how simple it's the final result

const RedHour = withOverride("color", "red")(HourPointer);

const Square = withStyle({
  borderRadius: 0,
})(ClockCircle);

function App(): JSX.Element {
  return (
    <>
      <div>
        <h1>The default clock</h1>
        <Clock />
      </div>
      <div>
        <h1>#1 Variant: without minute marks</h1>
        <Clock MinuteMarks={null} />
      </div>
      <div>
        <h1>#2 With a red hour pointer</h1>
        <Clock HourPointer={(): typeof RedHour => RedHour} />
      </div>
      <div>
        <h1>#3 Inside a square</h1>
        <Clock Circle={(): typeof Square => Square} />
      </div>
    </>
  );
}
removepackage.jsonclassestypefsclassnamelogging6to5validtranspilerstartflatMapshamwordwraphookformtaskfpexpressless mixinscss lessassertsgradients css3dependenciesmergecorebannerlimitmochaindicatores8openerupStreamautoprefixerlistenerswhichcommandopenbabel-coremkdirinvariantObservableswrapassertObject.valuesECMAScript 2016ttyUint16ArraymobilewalkbrowserlistprocessSymbolgettertypanioneslintpluginpicomatchi18nsortedcontainsStyleSheettoolkithardlinkscoercibleruntimeES2018debugBigInt64ArrayprefixpackagespecauthenticationentriesxtermdeletegetOwnPropertyDescriptorcmdRxsequencetc39eventsextendmatchAll@@toStringTagAsyncIteratornativecryptoeventEmittervalidationTypeScriptrm -rfmkdirplibphonenumberhttpszodwatchingES2021ESnextequalityeslint-pluginutilparseconcatreal-timegetreactpostcss-pluginECMAScript 2022figletcryptwarningcompile lessserializeWebSocketrobusttslibIteratorfullwidthUint8ClampedArrayavaArrayBuffer.prototype.slicenegativeslicerandomposedragcss-in-jsansisyntaxreducepolyfillwaitdatefindLastIndexjasmineECMAScript 2017patchbootstrap csssameValueZerosomeerrorthreemake dirvariables in cssfolderexpressionassertionio-tsexit-codeasyncES2016protochannelString.prototype.trimbcryptoffsetstreamsdefaultpromisesmacosemitxdg-opencompilerless compilerefficientprivate dataperformantutilitiesloggerenvironmentserializerchromiumwordbreakshrinkwrapwebreadtoobjectMicrosoftform-validationES7circularenderratelimitCSSStyleDeclarationsymbolstreams2letfunctionsymlinkswidthweaksetimmercurriedparenthooksstringifymrucharacterjsonschemaponyfillesfast-copyfixed-widthreact animationtypeerrorfastfast-cloneexit0helperstrimEnduninstallproppoint-freereducercheckArray.prototype.flatMapeditorobjWeakMapdataviewES3collection.es6intrinsiccensoraccessibilityfseventsaccessortypescriptlimitedpreserve-symlinksstyleUnderscorestructuredClonekeytoSortedRFC-6455lazygestureses-shimsTypedArrayECMAScript 7flagyuplastpiperangeerrorfull-widthchineseopenseslintconfigbundlingxdgastpreprocessorwebsiteidWebSocketsarraybufferterminalsetPrototypeOfiterationkeyssharedarraybufferstyleguideloadingtranspilefilepromiseresolvecolourES2022jsxwatchmapSetbddinstallerlesscssbyteLengthArraycurlexeclruanimationnope$.extendgenericsmakeArray.prototype.findLastInt32Arrayencryptionframeworksetterrapidbytesettingsspeedduplexmixinsunicodeutilitystylingrmcolorscallbindclass-validatorqssigintsanitizationestreetermArrayBufferfunctionsarktypeworkerrgbl10nregular expressionspawnstablearrayschaitypestimeES8positiveES2020cloneapollorequestslotinspectpuredescriptorsutilstouchmiddlewareminimaldataViewairbnbisnodegetPrototypeOfURLflagsfile systemJSONharmonyuser-streamscjkfetchjsonpathtrimfindLastwatcherwgetvaluesstarterconcatMapcode pointssafeparserutil.inspectsignallinktappathObject.isbootstrap lessmimetypesjwtdescriptionURLSearchParamssanitizeredactes2015Object.getPrototypeOfES5MapcolumnidleasciiinterruptsquerysearchurlregularprogressInt8ArraydirquotedeepcopyimmutableESlaunchpushhasregexredux-toolkitparentsreact posehandlersframerFloat32ArrayfiltervariterateECMAScript 2020fast-deep-clonees2017exeincludesfantasy-landcomputed-typespruneES6superagentECMAScript 6mkdirsgetintrinsicbluebirdjestconcurrencynameartdomtextbyteOffsetnodejslessinstallonceRxJSnpmvalue.envoutputiekoreanconnectsetImmediateformatcallbackdebuggerwriteconsolereadablestreampnpm9
1.0.0

11 days ago