How to use the rax.createContext function in rax

To help you get started, we’ve selected a few rax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alibaba / rax / packages / rax-server-renderer / src / __tests__ / renderToString.js View on Github external
it('render one Consumer use default context value', function() {
    const ThemeContext = createContext('light');

    function MyContext() {
      return (
        
        
      );
    };

    function MyContext2() {
      return (
        
          {value =&gt; <div>{value}</div>}
        
      );
    }
github alibaba / rax / packages / rax-server-renderer / src / __tests__ / renderToString.js View on Github external
it('render with context hook', () =&gt; {
    const NumberContext = createContext(5);

    function MyComponent() {
      const value = useContext(NumberContext);

      return (
        <div>The answer is {value}.</div>
      );
    };

    let str = renderToString();
    expect(str).toBe('<div>The answer is 5.</div>');
  });
github alibaba / rax / packages / rax-server-renderer / src / __tests__ / context.js View on Github external
it('multiple contexts', () =&gt; {
      const Theme = createContext('dark');
      const Language = createContext('french');
      class Parent extends Component {
        render() {
          return (
            
              
            
          );
        }
      }

      function Child() {
        return (
github alibaba / rax / packages / rax-server-renderer / src / __tests__ / context.js View on Github external
it('nested context unwinding', () =&gt; {
      const Theme = createContext('dark');
      const Language = createContext('french');

      const App = () =&gt; (
        <div>
          
            
              
                
                  {theme =&gt; <div id="theme1">{theme}</div>}
                
              
              
                {theme =&gt; <div id="theme2">{theme}</div>}
              
              
                
                  </div>
github alibaba / rax / packages / rax-server-renderer / src / __tests__ / context.js View on Github external
it('function context', () =&gt; {
      let Ctx = createContext();

      function Provider() {
        return (
          
            {this.props.children}
          
        );
      }

      function FnConsumer() {
        return useContext(Ctx);
      }

      const str = renderToString(
        
          <span></span>
github alibaba / rax / packages / rax-server-renderer / src / __tests__ / renderToString.js View on Github external
it('render with Context.Provider', () =&gt; {
    const ThemeContext = createContext('light');

    function MyContext() {
      return (
        
          
        
      );
    };

    function MyComponent() {
      const value = useContext(ThemeContext);
      return (
        <div>Current theme is {value}.</div>
      );
    };
github alibaba / rax / packages / rax-server-renderer / src / __tests__ / context.js View on Github external
beforeEach(() =&gt; {
      Context = createContext('none');

      class Parent extends Component {
        render() {
          return (
            
              {this.props.children}
            
          );
        }
      }
      Consumer = Context.Consumer;
      PurpleContextProvider = props =&gt; (
        {props.children}
      );
      RedContextProvider = props =&gt; (
        {props.children}