This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-12
Channels
- # aleph (3)
- # announcements (15)
- # architecture (6)
- # babashka (35)
- # babashka-sci-dev (10)
- # biff (5)
- # calva (9)
- # cherry (1)
- # cider (44)
- # clj-kondo (31)
- # cljfx (1)
- # clojure (108)
- # clojure-europe (32)
- # clojure-norway (12)
- # clojurescript (15)
- # conjure (3)
- # cursive (8)
- # datahike (1)
- # datalevin (19)
- # datascript (1)
- # datomic (59)
- # emacs (4)
- # graphql (3)
- # jobs (1)
- # luminus (6)
- # meander (9)
- # membrane (45)
- # nbb (67)
- # off-topic (16)
- # portal (3)
- # remote-jobs (1)
- # scittle (8)
- # shadow-cljs (46)
- # test-check (7)
- # tools-deps (5)
- # vim (63)
- # web-security (11)
- # xtdb (15)
Possibly a question for #beginners but here goes: idk what I’m doing wrong here:
(ns instances
(:require ["ink" :refer [render Text]]
["ink-table" :refer [Table]]
[reagent.core :as r]))
;; ...
(defn table-instances []
[:> Table {:data table-data} @state])
Could not resolve symbol: Table
[5:46 PM] I’m literally doing the same thing as the example for the Text component
[5:47 PM] (defn hello []
[:> Text {:color "green"} "Hello, world! " @state])
this doesn’t throw an errorThis is the example I wanted to do in cljs/nbb: https://github.com/maticzav/ink-table#usage
Can you do a console.log with Table
? It might be nil because of the $default
you might have to use
"#error {:message \"Could not resolve symbol: Table\", :data {:type :sci/error, :line nil, :column nil, :file nil, :phase \"analysis\"}}"
same thing
(ns instances
(:require ["ink" :refer [render Text]]
["ink-table$default" :refer [Table]]
[reagent.core :as r]))
(js/console.log Table)
{
"dependencies": {
"ink": "3.2.0",
"ink-table": "3.0.0",
"nbb": "0.7.132"
}
}
this is the package.json
yay that seems to have worked 🙂
{
Header: [Function: Header],
Cell: [Function: Cell],
Skeleton: [Function: Skeleton],
default: [class Table extends Component]
}
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
at App (<path>/instances/node_modules/ink/build/components/App.js:42:9)
@ULE3UT8Q5 You might have to write :f>
hmm it might be closer to this example: https://github.com/babashka/nbb/blob/main/examples/react-pdf/example.cljs
confusing indeed, wasn’t as simple as I thought 🙂
It is indeed confusing. This simple example works for me:
(ns script
(:require ["ink" :refer [render Text]]
["ink-table$default" :as Table]
[reagent.core :as r]))
(defn Basic []
[:> Text "Hello"])
(render (r/as-element [Basic]))
But this doesn't:
(defn Basic []
[:> Table {:data (clj->js [{:name "Name 1"}
{:name "Name 2"}])}])
(render (r/as-element [Basic]))
yeah I had made a mistake it is
(render (r/as-element [table-instances]))
not
(render r/as-element [table-instances])
is a keys need to be unique error?
puling reagent out of the equation:
(render (React.createElement Table (clj->js {:data [{:name "Name 1"}
{:name "Name 2"}]})))
I get the same error for:
import { render } from "ink";
import { createElement } from "react";
import Table from "ink-table";
render(createElement(Table));
This works:
(ns script
(:require ["ink" :refer [render Text]]
["ink-table$default.default" :as Table]
[reagent.core :as r]))
(render
(r/as-element [:> Table {:data (clj->js [{:name "Name 1"}
{:name "Name 2"}])}]))
cc @ULE3UT8Q5In JS:
import { render } from "ink";
import { createElement } from "react";
import Table from "ink-table";
const Basic = () => {
return createElement(Table.default, {data: [{name: "Hello"}]});
}
render(createElement(Basic));
whoa thanks @U04V15CAJ
it works for me too 🙂
so, how do you know to require it like this?
["ink-table$default.default" :as Table]
trial and error unfortunately. When you print Table
you see that it has another default
property
thanks, this is useful to know, I would have never thought to do default.default
Hello everyone! Quick question. Is there any way to load clojure(script) libraries other than having the source in the file system?
Oops never mind. Just saw the classpath workaround in the docs.
@U83GQU8LE You can specify deps in nbb.edn
now as well
Ooh checking out the PR and that looks much better indeed
And on the flip side, is it possible to directly require js files (not from node_modules)?
Do you mean something like:
(ns dev
(:require ["./foo.js" :refer [bar]]))
Hmm getting an error if I try it:
❯ npx nbb nrepl-server :port 40000
nREPL server started on port 40000 on host 127.0.0.1 -
(node:30355) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Yes, this is node behavior. you can rename your file to .mjs
or put "type": "module"
in your package.json
Ahh that works! Thanks! I should read up on this.
The rule on Node.js is that you cannot load common JS modules (regular .js files) from ES6 modules and nbb is an ES6 module
Hm. I'm honestly not very well aware on the module stuff with node. But I'm assuming anything with import/export = CJS?
Anything with import / export / await = ES6 module and should end either in .mjs or the default should be set with type = module
interesting. not something I've encountered before in JS code I've worked with. We use es6 but we neither have the type set to module or use mjs. I'm assuming this has something to do with bundling as to why neither is used in code that uses import/export/await.
Too many things made easy but not simple in js land ^^;
Ahh reading up on it and it's babel doing transpiling of the es modules
At least in our case