americanexpress / react-albus

✨ React component library for building declarative multi-step flows.
Apache License 2.0
1.1k stars 89 forks source link

Migration to React 16.x context #38

Open RusinovAnton opened 5 years ago

RusinovAnton commented 5 years ago

Hello, thanks for the great library.

Is it planned to migrate to the latest React versions, especially using stable context API?

cheungpat commented 4 years ago

As for React 16.x context, I created my own WizardContext which allows my code to get the albus context via the new 16.x API:

// WizardContext.tsx
import React from "react";
import PropTypes from 'prop-types';
import { WizardContext as AlbusContext } from 'react-albus';

export const WizardContext = React.createContext<AlbusContext>(
  {} as AlbusContext
);

export const WizardProvider: React.FC = ({children}, context) => {
  return (
    <WizardContext.Provider value={context.wizard}>
      {children}
    </WizardContext.Provider>
  );
};

WizardProvider.contextTypes = {
  wizard: PropTypes.object
};

Then in the wizard tsx:

import { WizardProvider } from './WizardContext';
// ...
<Wizard>
  <WizardProvider>
    <Steps>
// ...

Then in a child component tsx:

import { WizardContext } from '../contexts/WizardContext';
// ...
  const {
    next
  } = useContext(WizardContext);
// ...
  <button onClick={next}>Next</button>

Hope this helps. Still hoping 16.x context support will be added soon.

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 30 days with no activity. Remove no-issue-activity label or comment or this will be closed in 5 days.

paulocarvalho2899 commented 4 years ago

I have the same problem, it is important to do the migration!

@cheungpat is a good "solution", but it's only temporary

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 30 days with no activity.

ryhinchey commented 3 years ago

sorry for the late response here. We'll be updating to the latest React Context api soon

araymond11 commented 3 years ago

I have the same problem too, is it still supposed to be fixed soon ? Thanks !

dmossie commented 2 years ago

Hey I am also getting this warning - would be great to have an update!

paulosalvatore commented 2 years ago

@ryhinchey Any news?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity.

JAKWeRD commented 7 months ago

Hello, what has happened to this? Still getting this error.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 30 days with no activity.