Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Import a JSON file content" to "Import From JavaScript" page #200

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pages/docs/manual/latest/import-from-export-to-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ console.log(Student.default);

</CodeTab>

### Import a JSON file content

Use the `bs.module` [external](external.md):
Copy link
Contributor

@kevanstannard kevanstannard Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor: Since the bs.module and link is mentioned earlier in the page, what do you think about replacing this with a simple sentence such as "ReScript also provides built in support for reading JSON files." (similar to the couple of previous examples).


<CodeTab labels={["ReScript", "JS Output"]}>

```res example
type dataType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making this a Json type type dataType = Js.Json.t?

@bs.module external studentNames: dataType = "./students.json"
Js.log(studentNames)
```
```js
var StudentsJson = require("./students.json");
var studentNames = StudentsJson;
console.log(studentNames);
```

</CodeTab>

## Export To JavaScript

As mentioned in ReScript's idiomatic [Import & Export](import-export.md), every let binding and module is exported by default to other ReScript modules. If you open up the compiled JS file, you'll see that these values can also directly be used by another _JavaScript_ file too.
Expand Down