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",
    pre: "pre",
    code: "code",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsx(_components.p, {
      children: "You can always get a reference to a DOM element in Solid through assignment, since JSX creates actual DOM elements. For example:"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " myDiv = ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "div"
            }), ">"]
          }), "My Element", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "div"
            }), ">"]
          })]
        }), ";\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "However, there is benefit to not breaking your elements out and instead putting them in a single contiguous JSX template, as it allows Solid to better optimize their creation."
    }), "\n", jsxs(_components.p, {
      children: ["Instead you can get a reference to an element in Solid using the ", jsx(_components.code, {
        children: "ref"
      }), " attribute. Refs are basically assignments like the example above, which happen at creation time before they are attached to the document DOM. Just declare a variable, pass it in as a ", jsx(_components.code, {
        children: "ref"
      }), " attribute, and the variable will be assigned to:"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "let"
        }), " myDiv;\n\n", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "div"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "ref"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "{myDiv}"
            }), ">"]
          }), "My Element", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "div"
            }), ">"]
          })]
        }), "\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "So let's get a reference to our canvas element and animate it:"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<canvas ref={canvas} width=", jsx(_components.span, {
          className: "hljs-string",
          children: "\"256\""
        }), " height=", jsx(_components.span, {
          className: "hljs-string",
          children: "\"256\""
        }), " />\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "Refs can also take the form of a callback function. This can be convenient for encapsulating logic, especially when you don't need to wait until the elements are attached. For example:"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<div ref={", jsxs(_components.span, {
          className: "hljs-function",
          children: [jsx(_components.span, {
            className: "hljs-params",
            children: "el"
          }), " =>"]
        }), " ", jsx(_components.span, {
          className: "hljs-comment",
          children: "/* do something with el... */"
        }), "}>", jsx(_components.span, {
          className: "hljs-title class_",
          children: "My"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Element"
        }), "</div>\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-a3fa96de.js.map
