reactjs – ¿Cómo puedo renderizar un componente x veces?

Soy nuevo en React Native y no sé como puedo renderizar un componente varias veces, digamos que tengo un componente que es una caja, yo quiero que me renderize ese componente 9 veces por ejemplo.

Este es el componente que me da una caja, le he quitado los styles para no liar más.

class Box extends Component<Props> {
    render() {
        return (
            <View>
                <View>
                    <Text></Text>
                </View>
                <View>
                    <Text></Text>
                </View>
                <View>
                    <Text></Text>
                </View>
            </View>
        )
    }
}

Y llamo al componente anterior desde este otro componente:

class Prov extends Component<MyProps, MyState> {
    constructor(props: any) {
        super(props);
        this.state = {
            componentController: true}
    }
    changeStateTrue() {
       this.setState({componentController: true});
    }

    changeStateFalse() {
        this.setState({componentController: false});
    }

    render() {
        let renderComponent;
        const componentController = this.state.componentController;

        if (componentController) {
            renderComponent=<Box/>
        }

        return (
            <View>
                <View>
                    <TouchableOpacity onPress={() => this.changeStateTrue()}>
                        <Text> Por Aceptar  </Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={() => this.changeStateFalse()}>
                        <Text> En curso </Text>
                    </TouchableOpacity>
                </View>
                <View>
                    {renderComponent}
                </View>
            </View>
        )
    }
}

reactjs – endpoint – Page Not Found – when accessing directly

I’m using reactjs and hosting on netlify. I have an app which runs on a specific domain lets take for example johndoe.com

When you go to johndoe.com and then go to johndoe.com/contacts everything works fine.

But if you try to access johndoe.com/contact right away, it throws error Page Not Found Looks like you've followed a broken link or entered a URL that doesn't exist on this site. from netlify. Meanwhile if I do the same thing on my localhost everything works perfect.

What might be the issue here?

reactjs – react native : what is the way to change class component to function component in my example?

what is the way to change class component to function component in my example ?
in my example i try to change it to a function component but it doesnt works ,
I would be happy to some help with this issue .

import * as React from 'react';
import { Searchbar } from 'react-native-paper';

export default class MyComponent extends React.Component {
  state = {
    firstQuery: '',
  };

  render() {
    const { firstQuery } = this.state;
    return (
      <Searchbar
      style={{marginTop: 60}}
        placeholder="Search"
        onChangeText={query => { this.setState({ firstQuery: query }); }}
        value={firstQuery}
      />
    );
  }
}

Selling Fastani.net | ReactJS Site | 210k unique visitors | 5k registred users | Discord | NewProxyLists

Hello,
I’m the owner of fastani.net and I decided to sell fastani.net. Reason behind it is because covid19 hit too hard on me and my bills so i won’t be able to fund it anymore.
Domain Price & Info:
Domain Name: fastani.net
Registered With: namecheap (currently in moving to njall)
Expires: setember 2021
Price or Starting Bid: 150$
Methods of Payment: PayPal only
BIN (Buy It Now) Price: 200$
Proof of ownership: imgur.com/a/IWnesf5
Website:
– Files, Design, Scripts
Price: 250$ (non exclusive copy), exclusive is 999$
Servers: 8TB of uploaded content }
Discord server with 1400 members }
Price for both are 200$
OR BIN EVERYTHING FOR: 1200$
Site ownership fastani.net/wjunction.txt

 

Selling – Fastani.net | Streaming site | ReactJS | Automated | 210k Unique Visitors | NewProxyLists

Hello,
I’m the owner of FastAnime
The reason of putting it on sale is because of recent events and lack of site fundings.
Current price is 300$ (can be negotiable) per copy or 1,200$ for exclusive (exclusive includes 8TB of anime, 6k users, domain, 1400 members discord server.) – (domain can be bought seperatly for 150$)
Anyone interested can contact me though discord or email (support@fastani.net)
Discord: Wei Yi Yi#7256
Site domain is fastani.net

Prevent tooltip going out of screen reactjs

Here a small demo. There are a few block; hovering on each block appears a tooltip(orange rect). It doesn’t work correctly.

  • Tooltip doesn’t appear when it hovers at first time
  • The first tooltip is displayed from right side of block; correct case
    is displayed from left
  • Tooltip can disappear when block is hovered

I’m stuck with this issues, because tooltip appears when block is hovered, and it should calculate immediately coords and display it in the right position

const { useState, useEffect, useCallback } = React;

function App() {
  return (
    <div>
      <HoveredBlock index={1} />
      <HoveredBlock index={2} blockStyle={{ marginLeft: "5%" }} />
      <HoveredBlock index={3} blockStyle={{ marginLeft: "50%" }} />
    </div>
  );
}

function calcCoords(blockRect, hoverRect) {
  const docWidth = document.documentElement.clientWidth;

  const isLeft = blockRect.right + hoverRect.width > docWidth;
  const coords = {};

  if (!isLeft) {
    coords.x = blockRect.right;
    coords.y = blockRect.top;
    coords.type = "right";
  } else {
    coords.x = blockRect.left - 5 - hoverRect.width;
    coords.y = blockRect.top;
    coords.type = "left";
  }

  return coords;
}

function HoveredBlock({ index, blockStyle }) {
  const (blockRect, setBlockRect) = useState();
  const (hoverRect, setHoverRect) = useState();
  const (showHover, setShowHover) = useState(false);

  const (coords, setCoords) = useState();

  const blockRef = useCallback((node) => {
    if (node) {
      setBlockRect(node.getBoundingClientRect());
    }
  }, ());

  const hoverRef = useCallback(
    (node) => {
      if (showHover && node) {
        setHoverRect(node.getBoundingClientRect());
      }
    },
    (showHover)
  );

  useEffect(() => {
    if (showHover && hoverRect) {
      const coords = calcCoords(blockRect, hoverRect);

      setCoords(coords);
    }
  }, (hoverRect));
  
  const isHidden = !showHover || !coords ? 'hidden' : '';

  return (
    <div>
      <div
        ref={blockRef}
        className="block"
        style={blockStyle}
        onMouseEnter={() => setShowHover(true)}
        onMouseLeave={() => setShowHover(false)}
      >
      {index}
      </div>
      <div
        ref={hoverRef}
        className={'hover-block' + isHidden}
        style={{
          left: coords && coords.x,
          top: coords && coords.y
        }}
      />
    </div>
  );
}


const rootElement = document.getElementById("root");

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  rootElement
);
.block {
  width: 100px;
  height: 100px;
  background-color: aquamarine;
  margin-left: 82%;
}

.hover-block {
  position: fixed;
  width: 100px;
  height: 100px;
  background-color: coral;
}

.hidden {
  display: none;
}
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
  
<div id="root"></div>

reactjs – Styled components `createGlobalStyle` incorrectly overrides local style in tests

Reproduction here: https://codesandbox.io/s/react-playground-forked-5638j?file=/button.spec.js:202-223

Both tests (which are identical) should pass because the global style has less specificity than the margin set by styled.button. You can see it override correctly in the browser tab of codesandbox.

The second run of the same test fails due to window.getComputedStyle(button).margin returning 0px.
Does something need to be reset in beforeEach? I can’t see why the global style overrides the margin at all.

react.js – Using conditional if in react

I have the following code working fine:

rowData is an object and I want to display download button only if the completePathName is not null and hence I did the following which is working fine. I am wondering if I can improve the following code in some manner or the conditional if that I have used is fine?

buttonTemplate = (rowData: any, column: any)  => {
        //if(typeof rowData !=='undefined' && typeof rowData.completePathName !=='undefined'){
        if(rowData.completePathName === null){
            return (
            
              console.log("Inside first return  - testing rowData:"),
              console.log(rowData),
              console.log(rowData.completePathName),
                <div style={{textAlign: 'center', width: '6em'}}>
                        <span>
                            <Button type='button' icon="pi pi-pencil" style={{marginRight: '5px'}} onClick={(e) => this.handleClick(rowData, e)} tooltip='Edit'/>
                            <Button icon="pi pi-trash" style={{marginRight: '5px'}} tooltip='Delete' />
                            
                        </span>
                </div>
            );

        }
        else {
            return (
                
                console.log("Inside second return  - testing rowData:"),
                console.log(rowData),
                console.log(rowData.completePathName),
            
                <div style={{textAlign: 'center', width: '6em'}}>
                        <span>
                            <Button type='button' icon="pi pi-pencil" style={{marginRight: '5px'}} onClick={(e) => this.handleClick(rowData, e)} tooltip='Edit'/>
                            <Button icon="pi pi-trash" style={{marginRight: '5px'}} tooltip='Delete' />
                            <Button icon="pi pi-download" tooltip='Download' />
                            
                        </span>
                </div>
            );

        }
       
    }

reactjs – pageContext remains undefined in Gatsby JS

I’m following this tutorial for creating a multi language site based on Gatsby JS:

https://itnext.io/techniques-approaches-for-multi-language-gatsby-apps-8ba13ff433c5

I’m creating a ContextProvider as follows:

.pageContext.js

import React from 'react';
import { useTranslation } from 'react-i18next';

const PageContext = React.createContext({});

export const PageContextProvider = ({ children, pageContext }) => {
  const { i18n } = useTranslation();
  i18n.changeLanguage(pageContext.lang);

  return <PageContext.Provider value={pageContext}>{children}</PageContext.Provider>;
};

export const usePageContext = () => React.useContext(PageContext);

and this is my gatsby-node.js

const path = require('path')
const fs = require('fs-extra')
const _ = require('lodash')
const { createFilePath } = require('gatsby-source-filesystem')
const config = require('./gatsby-config')

exports.onCreatePage = async ({ page, actions: { createPage, deletePage } }) => {

  await deletePage(page);

  await Promise.all(
    config.siteMetadata.supportedLanguages.map(async lang => {
      
      const originalPath = page.path;
      const localizedPath = `/${lang}${page.path}`

      await createPage({
        ...page,
        path: localizedPath,
        context: {
          ...page.context,
          originalPath,
          lang,
        },
      });
    })
  );
};

The pages are getting created, but when I try to access them from the browser, I get this error:

TypeError: Cannot read property ‘lang’ of undefined

and it refers to line 8 of pageContext.js

So basically the pageContext remains undefined even though the onCreatePage does seem to work correctly.

I’ve been working to fix this all day, still no idea.
In case you can see help, thanks a lot.

React.js: Manifest: Line: 1, column: 1, Syntax error;

This is my manifest.json in public folder

{
  "short_name": "React App",
  "name": "Create React App Sample",
  "icons": [
    {
      "src": "favicon.ico",
      "sizes": "64x64 32x32 24x24 16x16",
      "type": "image/x-icon"
    },
    {
      "src": "logo192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "logo512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],
  "start_url": ".",
  "display": "standalone",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}

this link I have in the index.html

<link rel="manifest" crossorigin="use-credentials" href="%PUBLIC_URL%/manifest.json" />

I have done lists of work but problem still remainung…

  1. delete node_modules and package.lock.json file and run npm install in my terminal

  2. add crossorigin="use-credentials" into link tag on indext.html of public folder

  3. edited follwing object on manifest.json

    {
    "start_url": "./",
    "display": "standalone",
    "theme_color": "#000000",
    "background_color": "#ffffff"
    }

but nothing is solved yet….