import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [];
function _createMdxContent(props) {
  const _components = Object.assign({
    p: "p",
    em: "em",
    code: "code",
    pre: "pre",
    span: "span",
    blockquote: "blockquote",
    a: "a"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsxs(_components.p, {
      children: ["Signals are trackable values, but they are only one half of the equation. To complement those are observers that can be updated by those trackable values. An ", jsx(_components.em, {
        children: "effect"
      }), " is one such observer; it  runs a side effect that depends on signals."]
    }), "\n", jsxs(_components.p, {
      children: ["An effect can be created by importing ", jsx(_components.code, {
        children: "createEffect"
      }), " from ", jsx(_components.code, {
        children: "solid-js"
      }), " and providing it a function. The effect automatically subscribes to any signal that is read during the function's execution and reruns when any of them change."]
    }), "\n", jsxs(_components.p, {
      children: ["So let's create an Effect that reruns whenever ", jsx(_components.code, {
        children: "count"
      }), " changes:"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-title function_",
          children: "createEffect"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " {\n  ", jsx(_components.span, {
          className: "hljs-variable language_",
          children: "console"
        }), ".", jsx(_components.span, {
          className: "hljs-title function_",
          children: "log"
        }), "(", jsx(_components.span, {
          className: "hljs-string",
          children: "\"The count is now\""
        }), ", ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "count"
        }), "());\n});\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["To update our ", jsx(_components.code, {
        children: "count"
      }), " Signal, we'll attach a click handler on our button:"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<button onClick={", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setCount"
        }), "(", jsx(_components.span, {
          className: "hljs-title function_",
          children: "count"
        }), "() + ", jsx(_components.span, {
          className: "hljs-number",
          children: "1"
        }), ")}>", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Click"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Me"
        }), "</button>\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["Now clicking the button writes to the console. This is a relatively simple example, but to understand how Solid works, you should imagine that every expression in JSX is its own effect that re-executes whenever its dependent signals change. This is how all rendering works in Solid: from Solid's perspective, ", jsx(_components.em, {
        children: "all rendering is just a side effect of the reactive system"
      }), "."]
    }), "\n", jsxs(_components.blockquote, {
      children: ["\n", jsxs(_components.p, {
        children: ["Effects that developers create with ", jsx(_components.code, {
          children: "createEffect"
        }), " run after rendering has completed and are mostly used for scheduling updates that interact with the DOM. If you want to modify the DOM earlier, use ", jsx(_components.a, {
          href: "https://www.solidjs.com/docs/latest/api#createrendereffect",
          children: jsx(_components.code, {
            children: "createRenderEffect"
          })
        }), "."]
      }), "\n"]
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=lesson-ef79dfbd.js.map
