react_component

in lib/react/rails/component_mount.rb [29:66]


      def react_component(name, props = {}, options = {}, &block)
        options = { :tag => options } if options.is_a?(Symbol)
        if options.fetch(:camelize_props, camelize_props_switch)
          props = React.camelize_props(props)
        end

        prerender_options = options[:prerender]
        if prerender_options
          block = Proc.new{ concat(prerender_component(name, props, prerender_options)) }
        end

        html_options = options.reverse_merge(:data => {})
        unless prerender_options == :static
          html_options[:data].tap do |data|
            data[:react_class] = name
            data[:react_props] = (props.is_a?(String) ? props : props.to_json)
            data[:hydrate] = 't' if prerender_options

            num_components = @cache_ids.count { |c| c.start_with? name }
            data[:react_cache_id] = "#{name}-#{num_components}"
          end
        end
        html_tag = html_options[:tag] || :div

        
        html_options.except!(:tag, :prerender, :camelize_props)

        rendered_tag = content_tag(html_tag, '', html_options, &block)
        if React::ServerRendering.renderer_options[:replay_console]
          
          
          rendered_tag.sub!(/\n(<script class="react-rails-console-replay">.*<\/script>)<\/(\w+)>$/m,'</\2>\1')
          rendered_tag.html_safe
        else
          rendered_tag
        end
      end