Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react: render dynamic component from json

import React from "react";
import Foo from "./components/Foo";
import Bar from "./components/Bar";
 
const Components = {
  foo: Foo,
  bar: Bar
};
 
export default block => {
  // component does exist
  if (typeof Components[block.component] !== "undefined") {
    return React.createElement(Components[block.component], {
      key: block._uid,
      block: block
    });
  }
}
Source by www.storyblok.com #
 
PREVIOUS NEXT
Tagged: #render #dynamic #component #json
ADD COMMENT
Topic
Name
2+3 =