Changing react barcode format - reactjs

I am currently using the react-barcode package. It is currently using the format="CODE128" format, I needed to change it to use the Code 39 Barcode Font. How to I import the font to my react project and use it in the react-barcode component. If its not possible is there any other components I can use to achieve this.
Code:
import React, { Component } from 'react';
import Barcode from 'react-barcode';
class Posts extends Component {
render () {
return (
<div>
<Barcode value="http://github.com/kciter" />
</div>
);
}
}
export default (Posts);
Display of the
code128 barcode

React-barcode doesn't use a barcode font at all.
You can just, following the docs, set format="CODE39".
<Barcode value="123456" format="CODE39" />

Related

Element Selector in React Native

This is a sample ReactJS Code:
import React from 'react';
import './App.css';
function App() {
doument.getElementById("my-id1").innerHTML = "Some Text Here"
return (
<div className="App">
<p id="my-id1"></p>
</div>
);
}
export default App;
But while Running the syntax of document.getElementById() in React Native, I get a runtime error.
What should I use instead of document.getElementById() in React Native to achieve the exact same output
I see that you want to insert text in a html tag. In React props are used to tell the component what properties it will have, sample:
const SampleComponent = props => {
return (<p> {props.text} </p>)
};
in your component:
return (
<SampleComponent text = {"Hi world"} />
)
This is a basic pattern in designing a view using React or React native. Note that you must not use HTML in react native, you must use its native analogs (View, Text, TextInput for xample).
Hi I'm not sure what you want to try to do in React Native with that.Can you plz explain maybe I'll be able to help.
doument.getElementById("my-id1").innerHTML = "Some Text Here"
is not possible in react native.
You can use useState() or states in react native to do it.
Let me know if you need more information on that.

Semantic UI React not displaying

I am decently new to react and am now trying to add semantic ui to my website. Every time I try to load the components they show as regular html instead of how semantic ui is supposed to look.
Here is an example of a class I am exporting:
import React, { Component } from "react";
import {Radio} from 'semantic-ui-react';
const RadioExampleToggle = () => <Radio toggle />
class Contact extends Component {
render() {
return (
<div>
<h2>DEMO PAGE</h2>
<p>Just a demo.
</p>
{RadioExampleToggle()}
</div>
);
}
}
export default Contact;
This will show up as a regular radio button which is what I find weird. How do I get it to display the semantic UI versions.
Please try import CSS file from semantic-ui.
import 'semantic-ui-css/semantic.min.css'
Try this:
Put it in your index.js
const styleLink = document.createElement("link");
styleLink.rel = "stylesheet";
styleLink.href = "https://cdn.jsdelivr.net/npm/semantic-ui/dist/semantic.min.css";
document.head.appendChild(styleLink);
Doing it this way will also help you when your app offers theme switching functionality.
code sample

React : Import dynamic SVG

I want to import a different set of SVG icons based on my Branding variable.
I try something like this :
import { BRANDING } from 'BrandingBuilder';
import {`${BRANDING}-icons.svg`};
But I know React didn't support to import a {variable}. Is there a workaround ?
According to the React Docs:
You can
also import SVGs directly as React components. You can use either of
the two approaches. In your code it would look like this:
import { BRANDING } from 'BrandingBuilder';
import { ReactComponent as Logo } from `${BRANDING}-icons.svg`;
const App = () => (
<div>
{/* Logo is an actual React component */}
<Logo />
</div>
);

How to use Select in preact-material-components

Im using preact-material-components on PWA.
I want to add a Select Menu so I can do like this:
import { h, Component } from 'preact';
import Select from 'preact-material-components/Select';
import 'preact-material-components/Select/style.css';
and then
export default class Home extends Component {
render() {
return (
<div class={style.home}>
<h1>Home route</h1>
<Select>
<Select.Item>Frutas y Verduras</Select.Item>
<Select.Item>Farmacia</Select.Item>
<Select.Item>Comida Rapida</Select.Item>
<Select.Item>Limpieza</Select.Item>
</Select>
</div>
);
}
}
But the Select Menu is not looking good at all, I can see with dev tools that the styles are being imported but it looks like something is wrong with CSS, I'm new to React so I would like to know your opinion about this code.
If you are using this component individually, DO NOT FORGET to import 'preact-material-components/Menu/style.css' and 'preact-material-components/List/style.css'
from https://material.preactjs.com/component/select

react-bootstrap with other components

I'm trying to get familiar with react and web development. And made my first steps.
Right now I'm using react with react-bootstrap & css modules.
In the main.html I had to include the bootstrap.css file.
I would like to replace my searchbar with react-autosuggest
It seems like bootstrap is breaking the style of react-autosuggest. Is it possible to combine both? Or is it a bad practice?
That is my code where I tried to use both searchbars:
import React, {Component} from 'react';
import styles from './App.css';
import Search from "./Search/Search"
import SearchAuto from "./SearchAuto/SearchAuto"
class App extends Component {
render() {
return (
<div>
<div className={styles.App}>
<h1>Title</h1>
<Search onSearch={this.searchForAddress}/>
</div>
<SearchAuto onSearch={this.searchForAddress}/>
</div>
);
}
}
export default App;
Any help would be greatly appreciated!

Resources