Import Textblock for React
See original GitHub issueHello! First of all, this framework seems pretty cool. Thank you for that!
But I have some problem using it in a React app.
Expected behaviour in App.js:
import React, { Component } from "react";
import "./App.scss";
import Textblock from "textblock";
class App extends Component {
componentDidMount() {
Textblock([
{
target: "h3",
minWidth: 400,
maxWidth: 800,
minWidthFontSize: 18,
maxWidthFontSize: 24,
minWidthLineHeight: 1.33,
maxWidthLineHeight: 1.2,
units: "px"
}
]);
}
render() {
return
<div className="App">
<h3>This title scales perfectly based on Textblock</h3>
</div>
);
}
}
export default App;
I guess this is the ES6 way to do it. This is mentioned here: https://github.com/glyphic-co/textblock/issues/7#issuecomment-364515428 Current behavior As it seems now, I have to do this in e.g. index.html the old fashioned way.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13
Top Results From Across the Web
Getting started with React TextBox component
This section briefly explains about how to create a simple TextBox through CSS classes using Create React App . Dependencies.
Read more >Text
A React component for displaying text. Text supports nesting, styling, and touch handling. In the following example, the nested title and body ...
Read more >react-native-text-block
Start using react-native-text-block in your project by running `npm i ... RNTextBlockPackage; to the imports at the top of the file ...
Read more >Portable Text to React
import {PortableText} from '@portabletext/react' <PortableText value={[/* array ... value}) => { // `value` is the single Portable Text block of this header ...
Read more >Forms
We can combine the two by making the React state be the “single source of truth”. Then the React component that renders a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think a React importable component would be great, but I think some more changes should be made to suit the React paradigm. Perhaps the core functionality could be extracted into a shared file, and then a vanilla version and a react version can import the core. You could then add as many other flavours as you like when react is no longer the hottest thing in the world.
Steps to take to split into vanilla/react versions
@tinymachine , this solves the current problem. I just want to leave the solution for others to see:
Expected behaviour in App.js:
But I guess the expected behaviour is still my last post, using ES6 Modules. But the solution above will definitely work for now.